Skip to content

Commit c7017df

Browse files
authored
build: update dev-infra package and format mjs files (#23857)
Updates to the latest version of the `dev-infra` package and fixes that we weren't enforcing formatting on `.mjs` files.
1 parent 8f167ec commit c7017df

File tree

10 files changed

+63
-53
lines changed

10 files changed

+63
-53
lines changed

.prettierrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
"quoteProps": "preserve",
66
"bracketSpacing": false,
77
"arrowParens": "avoid",
8-
"embeddedLanguageFormatting": "off",
9-
}
8+
"embeddedLanguageFormatting": "off"
9+
}

integration/linker/link-packages-test.mjs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,19 @@ function testPackage(pkg) {
7676
ast: true,
7777
filename: diskFilePath,
7878
filenameRelative: debugFileName,
79-
plugins: [linkerPlugin]
79+
plugins: [linkerPlugin],
8080
});
8181

8282
// Naively check if there are any Angular declarations left that haven't been linked.
8383
traverse(ast, {
84-
Identifier: (astPath) => {
84+
Identifier: astPath => {
8585
if (astPath.node.name.startsWith('ɵɵngDeclare')) {
8686
throw astPath.buildCodeFrameError(
87-
'Found Angular declaration that has not been linked.', Error);
87+
'Found Angular declaration that has not been linked.',
88+
Error,
89+
);
8890
}
89-
}
91+
},
9092
});
9193

9294
passedFiles.push(debugFileName);
@@ -95,5 +97,5 @@ function testPackage(pkg) {
9597
}
9698
}
9799

98-
return {passedFiles, failures}
100+
return {passedFiles, failures};
99101
}

integration/npm-packages-from-runfiles.mjs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ export function getNpmPackagesFromRunfiles() {
2020
const workspacePath = 'angular_material/src';
2121
if (!runfilesManifestPath) {
2222
const packageRunfilesDir = path.join(process.env.RUNFILES, workspacePath);
23-
return fs.readdirSync(packageRunfilesDir)
23+
return fs
24+
.readdirSync(packageRunfilesDir)
2425
.map(name => ({name, pkgPath: path.join(packageRunfilesDir, name, 'npm_package/')}))
2526
.filter(({pkgPath}) => fs.existsSync(pkgPath));
2627
}
2728
const workspaceManifestPathRegex = new RegExp(`^${workspacePath}/[\\w-]+/npm_package$`);
28-
return fs.readFileSync(runfilesManifestPath, 'utf8')
29+
return fs
30+
.readFileSync(runfilesManifestPath, 'utf8')
2931
.split('\n')
3032
.map(mapping => mapping.split(' '))
3133
.filter(([runfilePath]) => runfilePath.match(workspaceManifestPathRegex))

integration/ts-compat/helpers.mjs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import {join} from 'path';
2-
import {unlinkSync} from 'fs';
1+
import {join} from 'path';
2+
import {unlinkSync} from 'fs';
33
import shelljs from 'shelljs';
4-
import {fork} from 'child_process';
5-
import {getNpmPackagesFromRunfiles} from '../npm-packages-from-runfiles.mjs';
4+
import {fork} from 'child_process';
5+
import {getNpmPackagesFromRunfiles} from '../npm-packages-from-runfiles.mjs';
66
import {runfiles} from '@bazel/runfiles';
77

88
// Exit if any command fails.
@@ -14,7 +14,8 @@ const npmPackages = getNpmPackagesFromRunfiles();
1414
const nodeModulesDir = runfiles.resolve('npm/node_modules');
1515
// Path to the generated file that imports all entry-points.
1616
const testFilePath = runfiles.resolveWorkspaceRelative(
17-
'integration/ts-compat/import-all-entry-points.ts');
17+
'integration/ts-compat/import-all-entry-points.ts',
18+
);
1819

1920
/**
2021
* Runs the TypeScript compatibility test with the specified tsc binary. The
@@ -40,17 +41,19 @@ export async function runTypeScriptCompatibilityTest(tscBinPath) {
4041
// Disables automatic type resolution. In non-sandbox environments, the node modules
4142
// are accessible and types could end up as part of the program.
4243
'--types',
43-
'--lib', 'es2015,dom',
44+
'--lib',
45+
'es2015,dom',
4446
// Ensures that `node_modules` can be resolved. By default, in sandbox environments the
4547
// node modules cannot be resolved because they are wrapped in the `npm/node_modules` folder
46-
'--baseUrl', nodeModulesDir,
47-
testFilePath
48+
'--baseUrl',
49+
nodeModulesDir,
50+
testFilePath,
4851
];
4952
// Run `tsc` to compile the project. The stdout/stderr output is inherited, so that
5053
// warnings and errors are printed to the console.
5154
const tscProcess = fork(tscBinPath, tscArgs, {stdio: 'inherit'});
5255

53-
tscProcess.on('exit', (exitCode) => {
56+
tscProcess.on('exit', exitCode => {
5457
// Remove symlinks to keep a clean repository state.
5558
for (const {name} of npmPackages) {
5659
console.info(`Removing link for "@angular/${name}"..`);
@@ -60,5 +63,4 @@ export async function runTypeScriptCompatibilityTest(tscBinPath) {
6063
exitCode === 0 ? resolve() : reject();
6164
});
6265
});
63-
};
64-
66+
}

scripts/create-legacy-tests-bundle.mjs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ const outFile = join(distDir, 'legacy-test-bundle.spec.js');
2121
const ngcBinFile = join(nodeModulesDir, '@angular/compiler-cli/bundles/src/bin/ngc.js');
2222
const legacyOutputDir = join(distDir, 'legacy-test-out');
2323

24-
2524
/**
2625
* This script builds the whole library in `angular/components` together with its
2726
* spec files into a single IIFE bundle.
@@ -72,10 +71,10 @@ async function compileSassFiles() {
7271
for (const file of sassFiles) {
7372
const outRelativePath = relative(projectDir, file).replace(/\.scss$/, '.css');
7473
const outPath = join(projectDir, outRelativePath);
75-
const task = renderSassFileAsync(file).then(async (content) => {
74+
const task = renderSassFileAsync(file).then(async content => {
7675
console.info('Compiled, now writing:', outRelativePath);
7776
await fs.promises.mkdir(dirname(outPath), {recursive: true});
78-
await fs.promises.writeFile(outPath, content)
77+
await fs.promises.writeFile(outPath, content);
7978
});
8079

8180
sassTasks.push(task);
@@ -93,7 +92,10 @@ async function compileSassFiles() {
9392
async function compileProjectWithNgtsc() {
9493
// Build the project with Ngtsc so that external resources are inlined.
9594
const ngcProcess = child_process.spawnSync(
96-
'node', [ngcBinFile, '--project', legacyTsconfigPath], {shell: true, stdio: 'inherit'});
95+
'node',
96+
[ngcBinFile, '--project', legacyTsconfigPath],
97+
{shell: true, stdio: 'inherit'},
98+
);
9799

98100
if (ngcProcess.error || ngcProcess.status !== 0) {
99101
throw Error('Unable to compile tests and library. See error above.');
@@ -137,9 +139,9 @@ async function createEntryPointSpecFile() {
137139
/** Helper function to render a Sass file asynchronously using promises. */
138140
async function renderSassFileAsync(inputFile) {
139141
return new Promise((resolve, reject) => {
140-
sass.render(
141-
{file: inputFile, includePaths: [nodeModulesDir]},
142-
(err, result) => err ? reject(err) : resolve(result.css));
142+
sass.render({file: inputFile, includePaths: [nodeModulesDir]}, (err, result) =>
143+
err ? reject(err) : resolve(result.css),
144+
);
143145
});
144146
}
145147

@@ -149,10 +151,11 @@ async function renderSassFileAsync(inputFile) {
149151
*/
150152
async function createResolveEsbuildPlugin() {
151153
return {
152-
name: 'ng-resolve-esbuild', setup: (build) => {
153-
build.onResolve({filter: /@angular\//}, async (args) => {
154+
name: 'ng-resolve-esbuild',
155+
setup: build => {
156+
build.onResolve({filter: /@angular\//}, async args => {
154157
const pkgName = args.path.substr('@angular/'.length);
155-
let resolvedPath = join(legacyOutputDir, pkgName)
158+
let resolvedPath = join(legacyOutputDir, pkgName);
156159
let stats = await statGraceful(resolvedPath);
157160

158161
// If the resolved path points to a directory, resolve the contained `index.js` file
@@ -168,8 +171,8 @@ async function createResolveEsbuildPlugin() {
168171

169172
return stats !== null ? {path: resolvedPath} : undefined;
170173
});
171-
}
172-
}
174+
},
175+
};
173176
}
174177

175178
/** Creates an ESBuild plugin that runs the Angular linker on framework packages. */
@@ -183,8 +186,8 @@ async function createLinkerEsbuildPlugin() {
183186

184187
return {
185188
name: 'ng-linker-esbuild',
186-
setup: (build) => {
187-
build.onLoad({filter: /fesm2020/}, async (args) => {
189+
setup: build => {
190+
build.onLoad({filter: /fesm2020/}, async args => {
188191
const filePath = args.path;
189192
const content = await fs.promises.readFile(filePath, 'utf8');
190193
const {code} = await transformAsync(content, {

scripts/github/fetch-workflow-artifact.mjs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ async function main() {
2020
run_id: workflowId,
2121
});
2222

23-
const matchArtifact = artifacts.data.artifacts.find(
24-
artifact => artifact.name === artifactName,
25-
);
23+
const matchArtifact = artifacts.data.artifacts.find(artifact => artifact.name === artifactName);
2624

2725
const download = await github.actions.downloadArtifact({
2826
owner,

tools/angular/create_linker_esbuild_plugin.mjs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,24 @@ function isNgDeclareCallExpression(nodePath) {
1616

1717
// Expect the `ngDeclare` identifier to be used as part of a property access that
1818
// is invoked within a call expression. e.g. `i0.ɵɵngDeclare<>`.
19-
return nodePath.parentPath?.type === 'MemberExpression' &&
20-
nodePath.parentPath.parentPath?.type === 'CallExpression';
19+
return (
20+
nodePath.parentPath?.type === 'MemberExpression' &&
21+
nodePath.parentPath.parentPath?.type === 'CallExpression'
22+
);
2123
}
2224

2325
/** Asserts that the given AST does not contain any Angular partial declaration. */
2426
async function assertNoPartialDeclaration(filePath, ast, traverseFn) {
2527
// Naively check if there are any Angular declarations left that haven't been linked.
2628
traverseFn(ast, {
27-
Identifier: (astPath) => {
29+
Identifier: astPath => {
2830
if (isNgDeclareCallExpression(astPath)) {
2931
throw astPath.buildCodeFrameError(
30-
`Found Angular declaration that has not been linked. ${filePath}`, Error);
32+
`Found Angular declaration that has not been linked. ${filePath}`,
33+
Error,
34+
);
3135
}
32-
}
36+
},
3337
});
3438
}
3539

@@ -57,8 +61,8 @@ export async function createLinkerEsbuildPlugin(filter, ensureNoPartialDeclarati
5761

5862
return {
5963
name: 'ng-linker-esbuild',
60-
setup: (build) => {
61-
build.onLoad({filter}, async (args) => {
64+
setup: build => {
65+
build.onLoad({filter}, async args => {
6266
const filePath = args.path;
6367
const content = await fs.promises.readFile(filePath, 'utf8');
6468
const {ast, code} = await babel.transformAsync(content, {

tools/angular/esbuild.config.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ export default {
1515
plugins: [
1616
// Only run the linker on `fesm2020/` bundles. This should not have an effect on
1717
// the bundle output, but helps speeding up ESBuild when it visits other modules.
18-
await createLinkerEsbuildPlugin(/fesm2020/)
19-
]
18+
await createLinkerEsbuildPlugin(/fesm2020/),
19+
],
2020
};

tools/esbuild/esbuild-amd-config.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import url from 'url';
22
import path from 'path';
33

44
/** Path to the ESBuild configuration maintained by the user. */
5-
const userConfigExecPath = "TMPL_CONFIG_PATH"
5+
const userConfigExecPath = 'TMPL_CONFIG_PATH';
66

77
/** User ESBuild config. Empty if none is loaded. */
88
let userConfig = {};
@@ -17,7 +17,7 @@ if (userConfigExecPath !== '') {
1717

1818
export default {
1919
...userConfig,
20-
globalName: "__exports",
20+
globalName: '__exports',
2121
format: 'iife',
2222
banner: {js: 'define("TMPL_MODULE_NAME", [], function() {'},
2323
footer: {js: 'return __exports;})'},

tools/spec-bundling/esbuild.config-tmpl.mjs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@
88

99
// Note: This needs to be a workspace manifest path as this ESBuild config
1010
// is generated and can end up in arbitrary Bazel packages.
11-
import {
12-
createLinkerEsbuildPlugin
13-
} from 'angular_material/tools/angular/create_linker_esbuild_plugin.mjs';
11+
import {createLinkerEsbuildPlugin} from 'angular_material/tools/angular/create_linker_esbuild_plugin.mjs';
1412

1513
// Conditionally, based on whether partial compilation is enabled, we run the
1614
// linker on all files part of the test.
17-
const plugins = TMPL_PARTIAL_COMPILATION_ENABLED ?
18-
[await createLinkerEsbuildPlugin(/.*/, /* ensureNoPartialDeclaration */ true)] : []
15+
const plugins = TMPL_PARTIAL_COMPILATION_ENABLED
16+
? [await createLinkerEsbuildPlugin(/.*/, /* ensureNoPartialDeclaration */ true)]
17+
: [];
1918

2019
export default {
2120
// `tslib` sets the `module` condition to resolve to ESM.

0 commit comments

Comments
 (0)