Skip to content

Commit 018b2da

Browse files
authored
bundle with tsup to strip out development code, check with bob (#1729)
1 parent c96ced1 commit 018b2da

File tree

11 files changed

+427
-68
lines changed

11 files changed

+427
-68
lines changed

.changeset/two-toys-give.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-eslint/eslint-plugin': minor
3+
---
4+
5+
bundle with tsup to strip out development code, check with bob

.eslintrc.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ module.exports = {
6161
},
6262
},
6363
{
64-
files: ['scripts/**'],
64+
files: ['scripts/**', '**/tsup.config.ts'],
6565
rules: {
6666
'no-console': 'off',
6767
},

.github/workflows/pr.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
uses: the-guild-org/shared-config/.github/workflows/release-snapshot.yml@main
1515
with:
1616
npmTag: alpha
17-
buildScript: build
17+
buildScript: prerelease
1818
nodeVersion: 18
1919
packageManager: pnpm
2020
secrets:

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@
55
"license": "MIT",
66
"private": true,
77
"scripts": {
8-
"build": "tsc && bob build",
8+
"build": "pnpm --filter @graphql-eslint/eslint-plugin build && bob check",
99
"ci:lint": "eslint --ignore-path .gitignore --output-file eslint_report.json --format json .",
1010
"create-rule": "tsx scripts/create-rule.ts",
1111
"generate:configs": "tsx scripts/generate-configs.ts",
1212
"lint": "eslint --ignore-path .gitignore .",
1313
"lint:prettier": "prettier --cache --check .",
14-
"postbuild": "cp -r README.md ./packages/plugin/dist/ && tsx scripts/postbuild.ts",
1514
"postinstall": "tsx scripts/patch-graphql.ts",
16-
"prebuild": "rimraf ./tsconfig.tsbuildinfo",
17-
"prerelease": "pnpm build",
15+
"prebuild": "rimraf tsconfig.tsbuildinfo",
16+
"prerelease": "NODE_ENV=production pnpm build",
1817
"prettier": "pnpm lint:prettier --write",
1918
"release": "changeset publish",
2019
"test": "vitest ."
@@ -40,6 +39,7 @@
4039
"prettier": "2.8.8",
4140
"prettier-plugin-tailwindcss": "0.2.8",
4241
"rimraf": "5.0.1",
42+
"tsup": "^7.1.0",
4343
"tsx": "3.12.7",
4444
"typescript": "5.1.6",
4545
"vitest": "0.30.1"

packages/plugin/package.json

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,38 @@
55
"repository": "https://github.com/B2o5T/graphql-eslint",
66
"author": "Dotan Simha <[email protected]>",
77
"license": "MIT",
8+
"engines": {
9+
"node": ">=12"
10+
},
811
"main": "dist/cjs/index.js",
912
"module": "dist/esm/index.js",
1013
"exports": {
1114
"./package.json": "./package.json",
1215
".": {
1316
"require": {
14-
"types": "./dist/typings/index.d.cts",
17+
"types": "./dist/cjs/index.d.ts",
1518
"default": "./dist/cjs/index.js"
1619
},
1720
"import": {
18-
"types": "./dist/typings/index.d.ts",
21+
"types": "./dist/esm/index.d.mts",
1922
"default": "./dist/esm/index.js"
2023
},
2124
"default": {
22-
"types": "./dist/typings/index.d.ts",
25+
"types": "./dist/esm/index.d.mts",
2326
"default": "./dist/esm/index.js"
2427
}
2528
}
2629
},
27-
"typings": "dist/typings/index.d.ts",
30+
"typings": "dist/esm/index.d.mts",
2831
"keywords": [
2932
"eslint",
3033
"eslintplugin",
3134
"eslint-plugin",
3235
"graphql"
3336
],
37+
"scripts": {
38+
"build": "tsup"
39+
},
3440
"peerDependencies": {
3541
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"
3642
},
@@ -64,6 +70,6 @@
6470
},
6571
"sideEffects": false,
6672
"typescript": {
67-
"definition": "dist/typings/index.d.ts"
73+
"definition": "dist/cjs/index.d.ts"
6874
}
6975
}

packages/plugin/tsconfig.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es2021",
4+
"module": "ESNext",
5+
"declaration": false,
6+
"noEmit": true,
7+
"esModuleInterop": true,
8+
"strict": true,
9+
"skipLibCheck": true,
10+
"allowJs": true,
11+
"moduleResolution": "node",
12+
"lib": ["ESNext"],
13+
"types": ["vitest/globals"],
14+
"resolveJsonModule": true
15+
}
16+
}

packages/plugin/tsup.config.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { defineConfig, Options } from 'tsup';
2+
import fs, { readFile, writeFile } from 'node:fs/promises';
3+
import path from 'node:path';
4+
import packageJson from './package.json';
5+
6+
const opts: Options = {
7+
entry: ['src/**/*.ts'],
8+
clean: true,
9+
bundle: false,
10+
dts: true,
11+
env: {
12+
...(process.env.NODE_ENV && { NODE_ENV: process.env.NODE_ENV }),
13+
},
14+
};
15+
16+
const CWD = process.cwd();
17+
export default defineConfig([
18+
{
19+
...opts,
20+
format: 'esm',
21+
outDir: 'dist/esm',
22+
outExtension: () => ({ js: '.js' }),
23+
async onSuccess() {
24+
await fs.copyFile(
25+
path.join(CWD, '..', '..', 'README.md'),
26+
path.join(CWD, 'dist', 'README.md'),
27+
);
28+
await fs.writeFile(path.join(CWD, 'dist', 'esm', 'package.json'), '{"type": "module"}');
29+
await fs.writeFile(
30+
path.join(CWD, 'dist', 'package.json'),
31+
JSON.stringify({ ...packageJson, devDependencies: undefined }).replaceAll('dist/', ''),
32+
);
33+
34+
const filePaths = [
35+
'estree-converter/utils.js',
36+
'rules/graphql-js-validation.js',
37+
'testkit.js',
38+
];
39+
await Promise.all(
40+
filePaths.map(async filePath => {
41+
const fullPath = path.join(CWD, 'dist', 'esm', filePath);
42+
const content = await readFile(fullPath, 'utf8');
43+
await writeFile(
44+
fullPath,
45+
`
46+
import { createRequire } from 'module';
47+
const require = createRequire(import.meta.url);
48+
${content}`.trimStart(),
49+
);
50+
}),
51+
);
52+
53+
console.log('✅ Success!');
54+
},
55+
},
56+
{
57+
...opts,
58+
format: 'cjs',
59+
outDir: 'dist/cjs',
60+
},
61+
]);

0 commit comments

Comments
 (0)