Skip to content

Commit fb1af79

Browse files
committed
Experiment with using mjs for one of our build scripts
1 parent d6d2122 commit fb1af79

2 files changed

Lines changed: 12 additions & 11 deletions

File tree

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,25 @@
22
* Copyright (c) Microsoft Corporation. All rights reserved.
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
5-
//@ts-check
6-
const cp = require('child_process');
7-
const fs = require('fs');
8-
const path = require('path');
5+
6+
import { spawn as _spawn } from 'child_process';
7+
import { readdirSync, readFileSync } from 'fs';
8+
import { join } from 'path';
9+
import url from 'url'
910

1011
async function spawn(cmd, args, opts) {
1112
return new Promise((c, e) => {
12-
const child = cp.spawn(cmd, args, { shell: true, stdio: 'inherit', env: process.env, ...opts });
13+
const child = _spawn(cmd, args, { shell: true, stdio: 'inherit', env: process.env, ...opts });
1314
child.on('close', code => code === 0 ? c() : e(`Returned ${code}`));
1415
});
1516
}
1617

1718
async function main() {
1819
await spawn('yarn', [], { cwd: 'extensions' });
1920

20-
for (const extension of fs.readdirSync('extensions')) {
21+
for (const extension of readdirSync('extensions')) {
2122
try {
22-
let packageJSON = JSON.parse(fs.readFileSync(path.join('extensions', extension, 'package.json')).toString());
23+
let packageJSON = JSON.parse(readFileSync(join('extensions', extension, 'package.json')).toString());
2324
if (!(packageJSON && packageJSON.scripts && packageJSON.scripts['update-grammar'])) {
2425
continue;
2526
}
@@ -33,13 +34,13 @@ async function main() {
3334
// run integration tests
3435

3536
if (process.platform === 'win32') {
36-
cp.spawn('.\\scripts\\test-integration.bat', [], { env: process.env, stdio: 'inherit' });
37+
_spawn('.\\scripts\\test-integration.bat', [], { env: process.env, stdio: 'inherit' });
3738
} else {
38-
cp.spawn('/bin/bash', ['./scripts/test-integration.sh'], { env: process.env, stdio: 'inherit' });
39+
_spawn('/bin/bash', ['./scripts/test-integration.sh'], { env: process.env, stdio: 'inherit' });
3940
}
4041
}
4142

42-
if (require.main === module) {
43+
if (import.meta.url === url.pathToFileURL(process.argv[1]).href) {
4344
main().catch(err => {
4445
console.error(err);
4546
process.exit(1);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"gulp": "node --max_old_space_size=8192 ./node_modules/gulp/bin/gulp.js",
3434
"electron": "node build/lib/electron",
3535
"7z": "7z",
36-
"update-grammars": "node build/npm/update-all-grammars.js",
36+
"update-grammars": "node build/npm/update-all-grammars.mjs",
3737
"update-localization-extension": "node build/npm/update-localization-extension.js",
3838
"smoketest": "node build/lib/preLaunch.js && cd test/smoke && yarn compile && node test/index.js",
3939
"smoketest-no-compile": "cd test/smoke && node test/index.js",

0 commit comments

Comments
 (0)