Skip to content

Commit 27693b5

Browse files
committed
fix: support esm syntax in lint checks
1 parent 20f26c9 commit 27693b5

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

scripts/lint.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,17 @@ function lintJson(filePath) {
3838
}
3939

4040
function lintSource(filePath) {
41-
const result = spawnSync(nodeCmd, ['--check', filePath], {
41+
const ext = path.extname(filePath).toLowerCase();
42+
const sourceText = fs.readFileSync(filePath, 'utf8');
43+
const normalized = stripUtf8Bom(sourceText);
44+
const treatsAsModule = ext === '.mjs'
45+
|| (ext === '.js' && /\b(?:import|export)\b|import\.meta/.test(normalized));
46+
const args = treatsAsModule
47+
? ['--input-type=module', '--check']
48+
: ['--check', filePath];
49+
const result = spawnSync(nodeCmd, args, {
4250
cwd: root,
51+
input: treatsAsModule ? normalized : undefined,
4352
encoding: 'utf8',
4453
env: process.env
4554
});

0 commit comments

Comments
 (0)