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

bundle with tsup to strip out development code, check with bob #1729

Merged
merged 7 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/two-toys-give.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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',
},
]);