Skip to content
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

Replace custom Rollup setup with tsup #1268

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
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
1 change: 1 addition & 0 deletions examples/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
23 changes: 17 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
{
"name": "superstruct",
"description": "A simple and composable way to validate data in JavaScript (and TypeScript).",
"version": "2.0.2",
"version": "2.0.3-1",
"license": "MIT",
"repository": "git://github.com/ianstormtaylor/superstruct.git",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
Comment on lines +9 to +16
Copy link

@MajorLift MajorLift Jul 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, this fix resolves the "Masquerading as ESM" issue that affected previous releases. This is demonstrated by the ATTW diagnostics results (before vs. after).

In the current JavaScript ecosystem, as long as "type": "module" is specified in package.json, there is no distinction between .js vs. .mjs and .d.ts vs. .d.mts files, so this should work without issue.

That said, all else being equal, I wonder if preferring explicit file extensions (exclusively using .mjs, .d.mts for ESM) would help future-proof the code against any potential breaking changes in the module system implementations of ECMAScript, Node.js, or TypeScript. Given the complicated, ongoing history of CJS/ESM-interop this doesn't seem like a remote possibility.

I'm curious whether you see any advantage in using the ambiguous .js, .d.ts extensions, or if you are indifferent between the two options?

"require": {
"types": "./dist/index.d.cts",
"default": "./dist/index.cjs"
}
}
},
"sideEffects": false,
"files": [
"dist"
Expand All @@ -19,7 +31,6 @@
"node": ">=14.0.0"
},
"devDependencies": {
"@rollup/plugin-typescript": "^11.1.6",
"@types/expect": "^24.3.0",
"@types/lodash": "^4.14.144",
"@types/node": "^18.7.14",
Expand All @@ -31,20 +42,20 @@
"lodash": "^4.17.15",
"np": "^10.0.0",
"prettier": "^3.2.5",
"rollup": "^4.12.1",
"tsup": "^8.2.3",
"typescript": "^4.8.3",
"vitest": "^1.6.0"
},
"scripts": {
"build": "rm -rf ./{dist} && rollup --config ./rollup.config.js",
"build": "rm -rf ./{dist} && tsup",
"clean": "rm -rf ./{dist,node_modules}",
"fix": "npm run fix:eslint && npm run fix:prettier",
"fix:eslint": "npm run lint:eslint --fix",
"fix:prettier": "prettier '**/*.{js,json,ts}' --write",
"lint": "npm run lint:eslint && npm run lint:prettier",
"lint:eslint": "eslint '{src,test}/*.{js,ts}'",
"lint:prettier": "prettier '**/*.{js,json,ts}' --check",
"release": "npm run build && npm run lint && np",
"release": "npm run build && npm run lint && np --any-branch",
"test": "npm run build && npm run test:types && npm run test:vitest",
"test:types": "tsc --noEmit && tsc --project ./test/tsconfig.json --noEmit",
"test:vitest": "vitest run",
Expand Down
20 changes: 0 additions & 20 deletions rollup.config.js

This file was deleted.

9 changes: 9 additions & 0 deletions tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from 'tsup'

export default defineConfig({
entry: ['src/index.ts'],
sourcemap: true,
dts: true,
format: ['cjs', 'esm', 'iife'],
globalName: 'Superstruct',
})