Skip to content

Commit

Permalink
chore(web): publint and attw (#10943)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobbe authored Jul 13, 2024
1 parent d39d278 commit d7a0a6a
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 38 deletions.
6 changes: 3 additions & 3 deletions packages/auth/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' }))

Expand Down
34 changes: 34 additions & 0 deletions packages/web/attw.ts
Original file line number Diff line number Diff line change
@@ -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)
16 changes: 11 additions & 5 deletions packages/web/build.mts → packages/web/build.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { writeFileSync } from 'node:fs'

import {
build,
defaultBuildOptions,
defaultIgnorePatterns,
} from '@redwoodjs/framework-tools'
import { writeFileSync } from 'node:fs'

// CJS build
/**
Expand All @@ -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,
Expand All @@ -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')
88 changes: 64 additions & 24 deletions packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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"
},
Expand All @@ -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",
Expand All @@ -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",
Expand Down
7 changes: 1 addition & 6 deletions packages/web/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@
"testing-library.d.ts"
],
"references": [
{
"path": "../auth/tsconfig.build.json"
},
{
"path": "../internal"
}
{ "path": "../internal" }
]
}
3 changes: 3 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down

0 comments on commit d7a0a6a

Please sign in to comment.