Skip to content

Commit

Permalink
Merge pull request #249 from remix-pwa/fix/cli
Browse files Browse the repository at this point in the history
fix(cli): added cross-support for Node pre-21 & Node 21.0.7+
  • Loading branch information
ShafSpecs authored Jul 21, 2024
2 parents 780be3a + b5f1c1b commit b3d13da
Showing 1 changed file with 33 additions and 6 deletions.
39 changes: 33 additions & 6 deletions packages/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,17 @@ process.emit = function (name, data, ..._args) {
return originalEmit.apply(process, arguments as unknown as Parameters<typeof process.emit>);
};

const packageJson = await import('./package.json', { with: { type: 'json' } });
let packageJson: any;
try {
packageJson = await import('./package.json', { assert: { type: 'json' } });
} catch (err) {
if ((err as any).code === 'ERR_IMPORT_ATTRIBUTE_MISSING') {
packageJson = await import('./package.json', { with: { type: 'json' } });
} else {
console.error('💥 Error occured:', '\n\n', err);
process.exit(1);
}
}

const { blue, bold, green, italic, magenta, red } = colors;
const { ModuleKind, ScriptTarget, transpileModule } = ts;
Expand Down Expand Up @@ -196,11 +206,28 @@ program
const root = resolve(process.cwd(), options.root);
const packagesToUpdate = options.packages ?? [];

const packageJSON = (
await import('file://' + fileURLToPath(`file:///${resolve(root, 'package.json').replace(/\\/g, '/')}`), {
with: { type: 'json' },
})
).default;
let packageJSON: any;
console.log(blue('🔃 Reading package.json file...'));

try {
packageJSON = (
await import('file://' + fileURLToPath(`file:///${resolve(root, 'package.json').replace(/\\/g, '/')}`), {
assert: { type: 'json' },
})
).default;
} catch (err) {
if ((err as any).code === 'ERR_IMPORT_ATTRIBUTE_MISSING') {
packageJSON = (
await import('file://' + fileURLToPath(`file:///${resolve(root, 'package.json').replace(/\\/g, '/')}`), {
with: { type: 'json' },
})
).default;
} else {
console.error(red(bold('💥 Error occured whilst reading package.json file:')), '\n\n', err);
process.exit(1);
}
}

const dependencies = packageJSON.dependencies;
const devDependencies = packageJSON.devDependencies;

Expand Down

0 comments on commit b3d13da

Please sign in to comment.