Skip to content

Commit

Permalink
Set package as ESM-frist and add Publint to better monitor package.js…
Browse files Browse the repository at this point in the history
…on correctness
  • Loading branch information
vnphanquang committed Nov 28, 2024
1 parent f5ac09f commit d3f6327
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 30 deletions.
5 changes: 5 additions & 0 deletions .changeset/soft-balloons-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@evilmartians/harmony": minor
---

set pacakge as ESM-first, prioritize ESM exports as `.js`, update CommonJS exports as `.cjs`, fix [publint](https://publint.dev/@evilmartians/[email protected]) recommendations
1 change: 1 addition & 0 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"tasks": {
"build": "deno run --allow-read --allow-write scripts/build.ts",
"publint": "deno run --allow-read --allow-env npm:publint",
"test": "deno test --allow-read --allow-write",
"update-snapshots": "deno test --allow-read --allow-write -- --update",
"changesets": "deno run -A npm:@changesets/cli",
Expand Down
91 changes: 89 additions & 2 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 11 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@
"name": "@evilmartians/harmony",
"version": "1.3.0",
"scripts": {
"build": "deno task build",
"build": "deno task build && deno task publint",
"prepublishOnly": "npm run build"
},
"main": "dist/index.js",
"type": "module",
"exports": {
"./tailwind": {
"types": "./dist/tailwind/index.d.ts",
"require": "./dist/tailwind/index.cjs",
"import": "./dist/tailwind/index.js",
"require": "./dist/tailwind/index.mjs",
"types": "./dist/tailwind/index.d.ts"
"default": "./dist/tailwind/index.js"
},
"./tailwind.css": "./dist/tailwind/index.css",
"./base": {
"import": "./dist/base/index.mjs",
"require": "./dist/base/index.js",
"types": "./dist/base/index.d.ts"
"types": "./dist/base/index.d.ts",
"require": "./dist/base/index.cjs",
"import": "./dist/base/index.js",
"default": "./dist/base/index.js"
},
"./css/*": "./dist/css/*"
},
Expand All @@ -30,7 +32,8 @@
"license": "MIT",
"devDependencies": {
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.9"
"@changesets/cli": "^2.27.9",
"publint": "^0.2.12"
},
"devEngines": {
"runtime": [
Expand Down
14 changes: 7 additions & 7 deletions scripts/targets/__snapshots__/base_test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export const snapshot = {};

snapshot[`base export 1`] = `
\`'use strict';
module.exports = {
'
export default {
"red": {
"100": "oklch(0.966797 0.0171875 20)",
"500": "oklch(0.742188 0.151562 20)"
Expand All @@ -11,13 +11,12 @@ module.exports = {
"100": "oklch(0.966797 0.0171875 43.3333)"
}
};
Object.defineProperty(exports, '__esModule', { value: true });
\`
'
`;

snapshot[`base export 2`] = `
'
export default {
\`'use strict';
module.exports = {
"red": {
"100": "oklch(0.966797 0.0171875 20)",
"500": "oklch(0.742188 0.151562 20)"
Expand All @@ -26,7 +25,8 @@ snapshot[`base export 2`] = `
"100": "oklch(0.966797 0.0171875 43.3333)"
}
};
'
Object.defineProperty(exports, '__esModule', { value: true });
\`
`;

snapshot[`base export 3`] = `
Expand Down
14 changes: 7 additions & 7 deletions scripts/targets/__snapshots__/tailwind_test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export const snapshot = {};

snapshot[`Tailwind export target 1`] = `
\`'use strict';
module.exports = {
'
export default {
"inherit": "inherit",
"current": "currentColor",
"transparent": "transparent",
Expand All @@ -16,13 +16,12 @@ module.exports = {
"100": "oklch(0.966797 0.0171875 43.3333 / <alpha-value>)"
}
};
Object.defineProperty(exports, '__esModule', { value: true });
\`
'
`;

snapshot[`Tailwind export target 2`] = `
'
export default {
\`'use strict';
module.exports = {
"inherit": "inherit",
"current": "currentColor",
"transparent": "transparent",
Expand All @@ -36,7 +35,8 @@ snapshot[`Tailwind export target 2`] = `
"100": "oklch(0.966797 0.0171875 43.3333 / <alpha-value>)"
}
};
'
Object.defineProperty(exports, '__esModule', { value: true });
\`
`;

snapshot[`Tailwind export target 3`] = `
Expand Down
4 changes: 2 additions & 2 deletions scripts/targets/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ export const buildBasicPalette: ExportTarget = async (
) => {
const palette = simplifyPalette(paletteWithFallback);
const content = generateCJS(palette);
await Deno.writeTextFile(path.join(targetDir, "index.js"), content);
await Deno.writeTextFile(path.join(targetDir, "index.cjs"), content);
await Deno.writeTextFile(
path.join(targetDir, "index.mjs"),
path.join(targetDir, "index.js"),
generateEsm(palette),
);
await Deno.writeTextFile(
Expand Down
2 changes: 1 addition & 1 deletion scripts/targets/base_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { testExportTarget } from "./testUtils.ts";
Deno.test("base export", async (t) => {
await testExportTarget(t, buildBasicPalette, [
"index.js",
"index.mjs",
"index.cjs",
"index.d.ts",
]);
});
4 changes: 2 additions & 2 deletions scripts/targets/tailwind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ export const buildTailwindPalette: ExportTarget = async (
};

const content = generateCJS(twPalette);
await Deno.writeTextFile(path.join(targetDir, "index.js"), content);
await Deno.writeTextFile(path.join(targetDir, "index.cjs"), content);
await Deno.writeTextFile(
path.join(targetDir, "index.mjs"),
path.join(targetDir, "index.js"),
generateEsm(twPalette),
);
await Deno.writeTextFile(
Expand Down
2 changes: 1 addition & 1 deletion scripts/targets/tailwind_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { testExportTarget } from "./testUtils.ts";
Deno.test("Tailwind export target", async (t) => {
await testExportTarget(t, buildTailwindPalette, [
"index.js",
"index.mjs",
"index.cjs",
"index.d.ts",
]);
});

0 comments on commit d3f6327

Please sign in to comment.