Skip to content

Commit

Permalink
fix: package.json asset type module setting (#733)
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Jul 22, 2021
1 parent 13dfe1b commit cd34f24
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
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"
}

0 comments on commit cd34f24

Please sign in to comment.