Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: package.json asset type module setting #733

Merged
merged 3 commits into from Jul 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/index.js
Expand Up @@ -531,7 +531,7 @@ function ncc (
const baseDir = dirname(filename);
const pjsonPath = (baseDir === '.' ? '' : baseDir) + 'package.json';
if (assets[pjsonPath])
assets[pjsonPath].source = JSON.stringify(Object.assign(JSON.parse(pjsonPath.source.toString()), { type: 'module' }));
assets[pjsonPath].source = JSON.stringify(Object.assign(JSON.parse(assets[pjsonPath].source.toString()), { type: 'module' }));
else
assets[pjsonPath] = { source: JSON.stringify({ type: 'module' }, null, 2) + '\n', permissions: defaultPermissions };
}
Expand Down
4 changes: 4 additions & 0 deletions test/cli.js
Expand Up @@ -11,6 +11,10 @@
args: ["run", "test/integration/test.ts"],
expect: { code: 0 }
},
{
args: ["build", "test/fixtures/type-module/main.js", "-o", "tmp"],
expect: { code: 0 }
},
{
args: ["build", "test/integration/test.ts", "-o", "tmp"],
expect (code, stdout, stderr) {
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/type-module/main.js
@@ -0,0 +1,6 @@
import { readFileSync } from 'fs';

readFileSync(new URL('./package.json', import.meta.url));

export var p = 5;

3 changes: 3 additions & 0 deletions test/fixtures/type-module/package.json
@@ -0,0 +1,3 @@
{
"type": "module"
}