Skip to content

Commit f819bf0

Browse files
devversionzarend
authored andcommitted
build: ensure schematic code runs as commonjs in NPM output
The CLI does not yet support running schematics as ESM. For this we actually still emit CommonJS output for schematics. We need to add a sub-directory `package.json` for the schematic folders though as otherwise NodeJS would incorrectly treat the `.js` schematic files as ESM due to the top-level package.json file setting `type: module`.
1 parent 0086925 commit f819bf0

File tree

5 files changed

+15
-1
lines changed

5 files changed

+15
-1
lines changed

src/cdk/schematics/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ ts_library(
4646
# This package is intended to be combined into the main @angular/cdk package as a dep.
4747
pkg_npm(
4848
name = "npm_package",
49+
srcs = ["package.json"],
4950
deps = [
5051
":schematics",
5152
":schematics_assets",

src/cdk/schematics/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"type": "commonjs"
3+
}

src/material/schematics/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ ts_library(
4444
# This package is intended to be combined into the main @angular/material package as a dep.
4545
pkg_npm(
4646
name = "npm_package",
47+
srcs = ["package.json"],
4748
deps = [
4849
":schematics",
4950
":schematics_assets",

src/material/schematics/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"type": "commonjs"
3+
}

tools/release-checks/npm-package-output/check-package.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {error} from '@angular/dev-infra-private/ng-dev/utils/console';
22
import * as chalk from 'chalk';
33
import {existsSync} from 'fs';
44
import {sync as glob} from 'glob';
5-
import {join} from 'path';
5+
import {basename, dirname, join} from 'path';
66

77
import {
88
checkCdkPackage,
@@ -63,6 +63,12 @@ export function checkReleasePackage(
6363
// Check each "package.json" file in the release output. We want to ensure
6464
// that there are no invalid file references in the entry-point definitions.
6565
packageJsonFiles.forEach(filePath => {
66+
// A `package.json` file part of the schematics folder is not considered an
67+
// entry-point `package.json` file and does not need to be checked.
68+
if (basename(dirname(filePath)) === 'schematics') {
69+
return;
70+
}
71+
6672
checkEntryPointPackageJsonFile(filePath).forEach(message => addFailure(message, filePath));
6773
});
6874

0 commit comments

Comments
 (0)