diff --git a/packages/auth/build.ts b/packages/auth/build.ts index f0265b9b48ae..cee4016df6f2 100644 --- a/packages/auth/build.ts +++ b/packages/auth/build.ts @@ -25,11 +25,11 @@ await build({ }, }) -// Place a package.json file with `type: commonjs` in the dist folder so that -// all .js files are treated as CommonJS files. +// Place a package.json file with `type: commonjs` in the dist/cjs folder so +// that all .js files are treated as CommonJS files. writeFileSync('dist/cjs/package.json', JSON.stringify({ type: 'commonjs' })) -// Place a package.json file with `type: module` in the dist/esm folder so that +// Place a package.json file with `type: module` in the dist folder so that // all .js files are treated as ES Module files. writeFileSync('dist/package.json', JSON.stringify({ type: 'module' })) diff --git a/packages/web/attw.ts b/packages/web/attw.ts new file mode 100644 index 000000000000..30cc6559892e --- /dev/null +++ b/packages/web/attw.ts @@ -0,0 +1,34 @@ +import { $ } from 'zx' + +interface Problem { + kind: string + entrypoint?: string + resolutionKind?: string +} + +await $({ nothrow: true })`yarn attw -P -f json > .attw.json` +const output = await $`cat .attw.json` +await $`rm .attw.json` + +const json = JSON.parse(output.stdout) + +if (!json.analysis.problems || json.analysis.problems.length === 0) { + console.log('No errors found') + process.exit(0) +} + +if ( + json.analysis.problems.every( + (problem: Problem) => + problem.resolutionKind === 'node10' || + problem.entrypoint === './webpackEntry' || + problem.entrypoint === './forceEsmApollo', + ) +) { + console.log("Only found problems we don't care about") + process.exit(0) +} + +console.log('Errors found') +console.log(json.analysis.problems) +process.exit(1) diff --git a/packages/web/build.mts b/packages/web/build.ts similarity index 71% rename from packages/web/build.mts rename to packages/web/build.ts index ad8cc749bae7..c481b2ec205e 100644 --- a/packages/web/build.mts +++ b/packages/web/build.ts @@ -1,9 +1,10 @@ +import { writeFileSync } from 'node:fs' + import { build, defaultBuildOptions, defaultIgnorePatterns, } from '@redwoodjs/framework-tools' -import { writeFileSync } from 'node:fs' // CJS build /** @@ -16,7 +17,7 @@ import { writeFileSync } from 'node:fs' */ await build({ entryPointOptions: { - ignore: [...defaultIgnorePatterns, 'src/__typetests__/**', 'src/entry/**'], + ignore: [...defaultIgnorePatterns, 'src/__typetests__/**'], //, 'src/entry/**'], }, buildOptions: { ...defaultBuildOptions, @@ -41,10 +42,15 @@ await build({ }, }) -// Place a package.json file with `type: commonjs` in the dist folder so that -// all .js files are treated as CommonJS files. +// Place a package.json file with `type: commonjs` in the dist/cjs folder so +// that all .js files are treated as CommonJS files. writeFileSync('dist/cjs/package.json', JSON.stringify({ type: 'commonjs' })) -// Place a package.json file with `type: module` in the dist/esm folder so that +// Place a package.json file with `type: module` in the dist folder so that // all .js files are treated as ES Module files. writeFileSync('dist/package.json', JSON.stringify({ type: 'module' })) + +// tsc doesn't generate any types here, because the source file is a javascript +// file. But it's really simple. It doesn't have any exports. So we can just +// write the type definitions ourselves +writeFileSync('dist/entry/index.d.ts', 'export {}\n') diff --git a/packages/web/package.json b/packages/web/package.json index a8a7554a4022..6a5b85b89202 100644 --- a/packages/web/package.json +++ b/packages/web/package.json @@ -22,30 +22,54 @@ }, "exports": { ".": { - "types": "./dist/index.d.ts", - "import": "./dist/index.js", - "require": "./dist/cjs/index.js" + "import": { + "types": "./dist/index.d.ts", + "default": "./dist/index.js" + }, + "require": { + "types": "./dist/cjs/index.d.ts", + "default": "./dist/cjs/index.js" + } }, "./serverInject": { - "types": "./dist/components/ServerInject.d.ts", - "import": "./dist/components/ServerInject.js", - "default": "./dist/cjs/components/ServerInject.js" + "import": { + "types": "./dist/components/ServerInject.d.ts", + "default": "./dist/components/ServerInject.js" + }, + "require": { + "types": "./dist/cjs/components/ServerInject.d.ts", + "default": "./dist/cjs/components/ServerInject.js" + } }, "./request": { - "types": "./dist/server/request.d.ts", - "import": "./dist/server/request.js", - "default": "./dist/cjs/server/request.js" + "import": { + "types": "./dist/server/request.d.ts", + "default": "./dist/server/request.js" + }, + "require": { + "types": "./dist/cjs/server/request.d.ts", + "default": "./dist/cjs/server/request.js" + } }, "./middleware": { - "types": "./dist/server/middleware.d.ts", - "import": "./dist/server/middleware.js", - "default": "./dist/cjs/server/middleware.js" + "import": { + "types": "./dist/server/middleware.d.ts", + "default": "./dist/server/middleware.js" + }, + "require": { + "types": "./dist/cjs/server/middleware.d.ts", + "default": "./dist/cjs/server/middleware.js" + } }, "./dist/server/middleware": { - "require": "./dist/cjs/server/middleware.js", - "types": "./dist/server/middleware.d.ts", - "import": "./dist/server/middleware.js", - "default": "./dist/cjs/server/middleware.js" + "import": { + "types": "./dist/server/middleware.d.ts", + "default": "./dist/server/middleware.js" + }, + "require": { + "types": "./dist/cjs/server/middleware.d.ts", + "default": "./dist/cjs/server/middleware.js" + } }, "./dist/components/*": { "require": "./dist/cjs/components/*.js", @@ -71,14 +95,24 @@ "default": "./dist/entry/index.js" }, "./toast": { - "types": "./dist/toast/index.d.ts", - "import": "./dist/toast/index.js", - "default": "./dist/cjs/toast/index.js" + "import": { + "types": "./dist/toast/index.d.ts", + "default": "./dist/toast/index.js" + }, + "require": { + "types": "./dist/cjs/toast/index.d.ts", + "default": "./dist/cjs/toast/index.js" + } }, "./apollo": { - "types": "./dist/apollo/index.d.ts", - "import": "./dist/apollo/index.js", - "default": "./dist/cjs/apollo/index.js" + "import": { + "types": "./dist/apollo/index.d.ts", + "default": "./dist/apollo/index.js" + }, + "require": { + "types": "./dist/cjs/apollo/index.d.ts", + "default": "./dist/cjs/apollo/index.js" + } }, "./forceEsmApollo": { "require": "./dist/apollo/index.js", @@ -92,12 +126,15 @@ "src/entry" ], "scripts": { - "build": "tsx ./build.mts && yarn build:types", + "build": "tsx ./build.ts && yarn build:types", "build:pack": "yarn pack -o redwoodjs-web.tgz", "build:types": "tsc --build --verbose ./tsconfig.json ./tsconfig.types-cjs.json", "build:watch": "nodemon --watch src --ext \"js,jsx,ts,tsx\" --ignore dist --exec \"yarn build\"", "prepublishOnly": "NODE_ENV=production yarn build", - "test": "vitest run", + "test": "concurrently npm:test:vitest npm:test:attw npm:test:publint", + "test:vitest": "vitest run", + "test:attw": "tsx ./attw.ts", + "test:publint": "yarn publint", "test:types": "tstyche", "test:watch": "vitest watch" }, @@ -118,6 +155,7 @@ }, "devDependencies": { "@apollo/client-react-streaming": "0.10.0", + "@arethetypeswrong/cli": "0.15.3", "@babel/cli": "7.24.5", "@babel/core": "^7.22.20", "@babel/plugin-transform-runtime": "7.24.3", @@ -129,7 +167,9 @@ "@testing-library/react": "14.3.1", "@types/react": "^18.2.55", "@types/react-dom": "^18.2.19", + "concurrently": "8.2.2", "nodemon": "3.1.3", + "publint": "0.2.8", "react": "19.0.0-beta-04b058868c-20240508", "react-dom": "19.0.0-beta-04b058868c-20240508", "tstyche": "2.0.0", diff --git a/packages/web/tsconfig.json b/packages/web/tsconfig.json index e1e11dacc0f5..6f5da81e0a26 100644 --- a/packages/web/tsconfig.json +++ b/packages/web/tsconfig.json @@ -13,11 +13,6 @@ "testing-library.d.ts" ], "references": [ - { - "path": "../auth/tsconfig.build.json" - }, - { - "path": "../internal" - } + { "path": "../internal" } ] } diff --git a/yarn.lock b/yarn.lock index 85fc878f61b3..6ad3aec90288 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8788,6 +8788,7 @@ __metadata: dependencies: "@apollo/client": "npm:3.9.9" "@apollo/client-react-streaming": "npm:0.10.0" + "@arethetypeswrong/cli": "npm:0.15.3" "@babel/cli": "npm:7.24.5" "@babel/core": "npm:^7.22.20" "@babel/plugin-transform-runtime": "npm:7.24.3" @@ -8803,11 +8804,13 @@ __metadata: "@types/react": "npm:^18.2.55" "@types/react-dom": "npm:^18.2.19" "@whatwg-node/fetch": "npm:0.9.17" + concurrently: "npm:8.2.2" core-js: "npm:3.37.1" graphql: "npm:16.8.1" graphql-sse: "npm:2.5.3" graphql-tag: "npm:2.12.6" nodemon: "npm:3.1.3" + publint: "npm:0.2.8" react: "npm:19.0.0-beta-04b058868c-20240508" react-dom: "npm:19.0.0-beta-04b058868c-20240508" react-helmet-async: "npm:2.0.5"