Skip to content

Commit

Permalink
bundle with tsup to strip out development code, check with bob (#1729)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaMachina committed Jul 4, 2023
1 parent c96ced1 commit 018b2da
Show file tree
Hide file tree
Showing 11 changed files with 427 additions and 68 deletions.
5 changes: 5 additions & 0 deletions .changeset/two-toys-give.md
@@ -0,0 +1,5 @@
---
'@graphql-eslint/eslint-plugin': minor
---

bundle with tsup to strip out development code, check with bob
2 changes: 1 addition & 1 deletion .eslintrc.cjs
Expand Up @@ -61,7 +61,7 @@ module.exports = {
},
},
{
files: ['scripts/**'],
files: ['scripts/**', '**/tsup.config.ts'],
rules: {
'no-console': 'off',
},
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr.yaml
Expand Up @@ -14,7 +14,7 @@ jobs:
uses: the-guild-org/shared-config/.github/workflows/release-snapshot.yml@main
with:
npmTag: alpha
buildScript: build
buildScript: prerelease
nodeVersion: 18
packageManager: pnpm
secrets:
Expand Down
8 changes: 4 additions & 4 deletions package.json
Expand Up @@ -5,16 +5,15 @@
"license": "MIT",
"private": true,
"scripts": {
"build": "tsc && bob build",
"build": "pnpm --filter @graphql-eslint/eslint-plugin build && bob check",
"ci:lint": "eslint --ignore-path .gitignore --output-file eslint_report.json --format json .",
"create-rule": "tsx scripts/create-rule.ts",
"generate:configs": "tsx scripts/generate-configs.ts",
"lint": "eslint --ignore-path .gitignore .",
"lint:prettier": "prettier --cache --check .",
"postbuild": "cp -r README.md ./packages/plugin/dist/ && tsx scripts/postbuild.ts",
"postinstall": "tsx scripts/patch-graphql.ts",
"prebuild": "rimraf ./tsconfig.tsbuildinfo",
"prerelease": "pnpm build",
"prebuild": "rimraf tsconfig.tsbuildinfo",
"prerelease": "NODE_ENV=production pnpm build",
"prettier": "pnpm lint:prettier --write",
"release": "changeset publish",
"test": "vitest ."
Expand All @@ -40,6 +39,7 @@
"prettier": "2.8.8",
"prettier-plugin-tailwindcss": "0.2.8",
"rimraf": "5.0.1",
"tsup": "^7.1.0",
"tsx": "3.12.7",
"typescript": "5.1.6",
"vitest": "0.30.1"
Expand Down
16 changes: 11 additions & 5 deletions packages/plugin/package.json
Expand Up @@ -5,32 +5,38 @@
"repository": "https://github.com/B2o5T/graphql-eslint",
"author": "Dotan Simha <dotansimha@gmail.com>",
"license": "MIT",
"engines": {
"node": ">=12"
},
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"exports": {
"./package.json": "./package.json",
".": {
"require": {
"types": "./dist/typings/index.d.cts",
"types": "./dist/cjs/index.d.ts",
"default": "./dist/cjs/index.js"
},
"import": {
"types": "./dist/typings/index.d.ts",
"types": "./dist/esm/index.d.mts",
"default": "./dist/esm/index.js"
},
"default": {
"types": "./dist/typings/index.d.ts",
"types": "./dist/esm/index.d.mts",
"default": "./dist/esm/index.js"
}
}
},
"typings": "dist/typings/index.d.ts",
"typings": "dist/esm/index.d.mts",
"keywords": [
"eslint",
"eslintplugin",
"eslint-plugin",
"graphql"
],
"scripts": {
"build": "tsup"
},
"peerDependencies": {
"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"
},
Expand Down Expand Up @@ -64,6 +70,6 @@
},
"sideEffects": false,
"typescript": {
"definition": "dist/typings/index.d.ts"
"definition": "dist/cjs/index.d.ts"
}
}
16 changes: 16 additions & 0 deletions packages/plugin/tsconfig.json
@@ -0,0 +1,16 @@
{
"compilerOptions": {
"target": "es2021",
"module": "ESNext",
"declaration": false,
"noEmit": true,
"esModuleInterop": true,
"strict": true,
"skipLibCheck": true,
"allowJs": true,
"moduleResolution": "node",
"lib": ["ESNext"],
"types": ["vitest/globals"],
"resolveJsonModule": true
}
}
61 changes: 61 additions & 0 deletions packages/plugin/tsup.config.ts
@@ -0,0 +1,61 @@
import { defineConfig, Options } from 'tsup';
import fs, { readFile, writeFile } from 'node:fs/promises';
import path from 'node:path';
import packageJson from './package.json';

const opts: Options = {
entry: ['src/**/*.ts'],
clean: true,
bundle: false,
dts: true,
env: {
...(process.env.NODE_ENV && { NODE_ENV: process.env.NODE_ENV }),
},
};

const CWD = process.cwd();
export default defineConfig([
{
...opts,
format: 'esm',
outDir: 'dist/esm',
outExtension: () => ({ js: '.js' }),
async onSuccess() {
await fs.copyFile(
path.join(CWD, '..', '..', 'README.md'),
path.join(CWD, 'dist', 'README.md'),
);
await fs.writeFile(path.join(CWD, 'dist', 'esm', 'package.json'), '{"type": "module"}');
await fs.writeFile(
path.join(CWD, 'dist', 'package.json'),
JSON.stringify({ ...packageJson, devDependencies: undefined }).replaceAll('dist/', ''),
);

const filePaths = [
'estree-converter/utils.js',
'rules/graphql-js-validation.js',
'testkit.js',
];
await Promise.all(
filePaths.map(async filePath => {
const fullPath = path.join(CWD, 'dist', 'esm', filePath);
const content = await readFile(fullPath, 'utf8');
await writeFile(
fullPath,
`
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
${content}`.trimStart(),
);
}),
);

console.log('✅ Success!');
},
},
{
...opts,
format: 'cjs',
outDir: 'dist/cjs',
},
]);

0 comments on commit 018b2da

Please sign in to comment.