Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"presets": [
"@babel/preset-env",
["@babel/preset-env", { "modules": false }],
"@babel/preset-typescript",
["babel-preset-solid", { "generate": "dom", "hydratable": true }]
]
}
}
5 changes: 5 additions & 0 deletions .changeset/esm-dist-modules-false.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@solidjs/meta": patch
---

Ship `dist/index.js` as ESM so Node/tsx/esbuild can load the package under `"type": "module"` (solidjs/solid-meta#83).
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"scripts": {
"prebuild": "npm run clean",
"clean": "rimraf dist/",
"build": "tsc && babel src/index.tsx --out-file dist/index.js",
"build": "tsc && babel src/index.tsx --out-file dist/index.js && node scripts/check-dist-esm.mjs",
"test": "npm run test:unit && npm run test:types",
"test:unit": "vitest run",
"test:watch": "vitest",
Expand Down
29 changes: 29 additions & 0 deletions scripts/check-dist-esm.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { readFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";

// #83 — package.json is `"type": "module"` and exports `./dist/index.js` as
// `"default"`. Babel must leave that file as ESM; CommonJS (`exports` /
// `require` / `module.exports`) breaks Node, tsx, and esbuild without the
// `solid` condition.
const dist = join(dirname(fileURLToPath(import.meta.url)), "..", "dist", "index.js");
const src = readFileSync(dist, "utf8");

const cjsPatterns = [
/Object\.defineProperty\(\s*exports\b/,
/^\s*exports\./m,
/\bmodule\.exports\b/,
/\brequire\s*\(/
];

if (cjsPatterns.some((re) => re.test(src))) {
console.error("dist/index.js is CommonJS; expected ESM (see solidjs/solid-meta#83)");
process.exit(1);
}

if (!/\bexport\s+(?:\{|var|let|const|function|class|default)\b/.test(src)) {
console.error("dist/index.js has no ESM export declarations");
process.exit(1);
}

console.log("dist/index.js is ESM");