diff --git a/.babelrc b/.babelrc index 8345fb7..1704fdd 100644 --- a/.babelrc +++ b/.babelrc @@ -1,7 +1,7 @@ { "presets": [ - "@babel/preset-env", + ["@babel/preset-env", { "modules": false }], "@babel/preset-typescript", ["babel-preset-solid", { "generate": "dom", "hydratable": true }] ] -} \ No newline at end of file +} diff --git a/.changeset/esm-dist-modules-false.md b/.changeset/esm-dist-modules-false.md new file mode 100644 index 0000000..95aaa24 --- /dev/null +++ b/.changeset/esm-dist-modules-false.md @@ -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). diff --git a/package.json b/package.json index aef5d21..c52989d 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/scripts/check-dist-esm.mjs b/scripts/check-dist-esm.mjs new file mode 100644 index 0000000..0d03da3 --- /dev/null +++ b/scripts/check-dist-esm.mjs @@ -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");