Skip to content

fix: make asinit exit if package.json has a "type" not equal to "module" #2938

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

Merged
merged 1 commit into from
Aug 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion bin/asinit.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,23 @@ const paths = [
[gitignoreFile, "Git configuration that excludes compiled binaries from source control."],
[asconfigFile, "Configuration file defining both a 'debug' and a 'release' target."],
[packageFile, "Package info containing the necessary commands to compile to WebAssembly."],
[testsIndexFile, "Stater test to check that the module is functioning."],
[testsIndexFile, "Starter test to check that the module is functioning."],
[indexHtmlFile, "Starter HTML file that loads the module in a browser."]
];

const formatPath = filePath => "./" + path.relative(projectDir, filePath).replace(/\\/g, "/");

if (fs.existsSync(packageFile)) {
const pkg = JSON.parse(fs.readFileSync(packageFile));
if ("type" in pkg && pkg["type"] !== "module") {
console.error(stdoutColors.red([
`Error: The "type" field in ${formatPath(packageFile)} is set to "${pkg["type"]}".`,
` asinit requires the "type" field to be set to "module" (ES modules).`
].join("\n")));
process.exit(1);
}
}

console.log([
"Version: " + version,
"",
Expand Down
Loading