build: refactor build system (#8324)

This commit is contained in:
Noel 2022-07-20 16:36:42 +02:00 committed by GitHub
parent d1245418f9
commit 3b0197bd8e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 1120 additions and 338 deletions

View file

@ -0,0 +1,36 @@
diff --git a/dist/rollup-plugin-typescript2.cjs.js b/dist/rollup-plugin-typescript2.cjs.js
index 9ab972b041cc76f8f786d6a20f3efb53c364cad6..13e056a3c0971eb18b307d91fad096a9f3b9de79 100644
--- a/dist/rollup-plugin-typescript2.cjs.js
+++ b/dist/rollup-plugin-typescript2.cjs.js
@@ -29799,6 +29799,13 @@ const typescript = (options) => {
declarations[key] = { type: result.dts, map: result.dtsmap };
context.debug(() => `${safe.exports.blue("generated declarations")} for '${key}'`);
}
+ // if a user sets this compilerOption, they probably want another plugin (e.g. Babel, ESBuild) to transform their TS instead, while rpt2 just type-checks and/or outputs declarations
+ // note that result.code is non-existent if emitDeclarationOnly per https://github.com/ezolenko/rollup-plugin-typescript2/issues/268
+ if (parsedConfig.options.emitDeclarationOnly)
+ {
+ context.debug(() => `${blue("emitDeclarationOnly")} enabled, not transforming TS'`);
+ return undefined;
+ }
const transformResult = { code: result.code, map: { mappings: "" } };
if (result.map) {
if (pluginOptions.sourceMapCallback)
diff --git a/dist/rollup-plugin-typescript2.es.js b/dist/rollup-plugin-typescript2.es.js
index e43bf8f03bc6792b61d8352e04bb6466712426c2..420e8f0d0d109076bc72e9d60240077235a9ba11 100644
--- a/dist/rollup-plugin-typescript2.es.js
+++ b/dist/rollup-plugin-typescript2.es.js
@@ -29770,6 +29770,13 @@ const typescript = (options) => {
declarations[key] = { type: result.dts, map: result.dtsmap };
context.debug(() => `${safe.exports.blue("generated declarations")} for '${key}'`);
}
+ // if a user sets this compilerOption, they probably want another plugin (e.g. Babel, ESBuild) to transform their TS instead, while rpt2 just type-checks and/or outputs declarations
+ // note that result.code is non-existent if emitDeclarationOnly per https://github.com/ezolenko/rollup-plugin-typescript2/issues/268
+ if (parsedConfig.options.emitDeclarationOnly)
+ {
+ context.debug(() => `${blue("emitDeclarationOnly")} enabled, not transforming TS'`);
+ return undefined;
+ }
const transformResult = { code: result.code, map: { mappings: "" } };
if (result.map) {
if (pluginOptions.sourceMapCallback)

93
build.config.ts Normal file
View file

@ -0,0 +1,93 @@
import { relative, resolve } from 'node:path';
import glob from 'fast-glob';
import typescript from 'rollup-plugin-typescript2';
import { defineBuildConfig, BuildEntry } from 'unbuild';
interface ConfigOptions {
entries: (BuildEntry | string)[];
minify: boolean;
emitCJS: boolean;
externals: string[];
cjsBridge: boolean;
sourcemap: boolean;
preserveModules: boolean;
preserveModulesRoot: string;
declaration: boolean;
typeCheck: boolean;
}
export function createUnbuildConfig({
entries = [{ builder: 'rollup', input: 'src/index' }],
minify = false,
emitCJS = true,
cjsBridge = true,
externals = [],
sourcemap = true,
preserveModules = true,
preserveModulesRoot = 'src',
declaration = true,
typeCheck = false,
}: Partial<ConfigOptions> = {}) {
const files = glob
.sync('**', { cwd: 'src' })
.map((file) => [`${file.slice(0, -2)}cjs`, `${file.slice(0, -2)}mjs`])
.flat();
return defineBuildConfig({
entries,
clean: true,
rollup: {
esbuild: {
minify,
minifyIdentifiers: false,
},
emitCJS,
cjsBridge,
json: {
namedExports: false,
},
},
externals: [...files, ...externals],
hooks: {
'rollup:options': (_, options) => {
// @ts-expect-error: This will always be an array
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
options.output![0] = {
// @ts-expect-error: This will always be an array
...options.output![0],
sourcemap,
preserveModules,
preserveModulesRoot,
};
if (emitCJS) {
// @ts-expect-error: This will always be an array
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
options.output![1] = {
// @ts-expect-error: This will always be an array
...options.output![1],
sourcemap,
preserveModules,
preserveModulesRoot,
};
}
if (declaration) {
options.plugins?.unshift(
typescript({
check: typeCheck,
tsconfig: relative(__dirname, resolve(process.cwd(), 'tsconfig.json')),
tsconfigOverride: {
compilerOptions: {
emitDeclarationOnly: true,
},
},
}),
);
}
},
},
});
}

View file

@ -41,19 +41,23 @@
"@commitlint/config-angular": "^17.0.3",
"@favware/cliff-jumper": "^1.8.5",
"@favware/npm-deprecate": "^1.0.4",
"@typescript-eslint/eslint-plugin": "^5.30.6",
"@typescript-eslint/parser": "^5.30.6",
"@typescript-eslint/eslint-plugin": "^5.30.7",
"@typescript-eslint/parser": "^5.30.7",
"conventional-changelog-cli": "^2.2.2",
"eslint": "^8.20.0",
"eslint-config-marine": "^9.4.1",
"eslint-config-prettier": "^8.5.0",
"eslint-import-resolver-typescript": "^3.2.7",
"eslint-import-resolver-typescript": "^3.3.0",
"eslint-plugin-import": "^2.26.0",
"fast-glob": "^3.2.11",
"husky": "^8.0.1",
"is-ci": "^3.0.1",
"prettier": "^2.7.1",
"typescript": "^4.7.4"
},
"resolutions": {
"rollup-plugin-typescript2@0.32.1": "patch:rollup-plugin-typescript2@npm:0.32.1#.yarn/patches/rollup-plugin-typescript2-npm-0.32.1-b5887420f2.patch"
},
"engines": {
"node": ">=16.9.0"
},

View file

@ -0,0 +1,3 @@
import { createUnbuildConfig } from '../../build.config';
export default createUnbuildConfig({ minify: true });

View file

@ -5,17 +5,17 @@
"private": true,
"scripts": {
"test": "vitest run",
"build": "tsup",
"build": "unbuild",
"lint": "prettier --check . && eslint src __tests__ --ext mjs,js,ts",
"format": "prettier --write . && eslint src __tests__ --ext mjs,js,ts --fix",
"fmt": "yarn format"
},
"main": "./dist/index.js",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"exports": {
"import": "./dist/index.mjs",
"require": "./dist/index.js",
"require": "./dist/index.cjs",
"types": "./dist/index.d.ts"
},
"directories": {
@ -50,11 +50,13 @@
},
"devDependencies": {
"@types/node": "^16.11.45",
"c8": "^7.11.3",
"c8": "^7.12.0",
"eslint": "^8.20.0",
"prettier": "^2.7.1",
"rollup-plugin-typescript2": "0.32.1",
"tsup": "^6.1.3",
"typescript": "^4.7.4",
"unbuild": "^0.7.4",
"vitest": "^0.18.1"
},
"engines": {

View file

@ -0,0 +1,3 @@
import { createUnbuildConfig } from '../../build.config';
export default createUnbuildConfig();

View file

@ -4,7 +4,7 @@
"description": "A set of builders that you can use when creating your bot",
"scripts": {
"test": "vitest run",
"build": "tsup",
"build": "unbuild",
"lint": "prettier --check . && eslint src __tests__ --ext mjs,js,ts",
"format": "prettier --write . && eslint src __tests__ --ext mjs,js,ts --fix",
"fmt": "yarn format",
@ -13,12 +13,12 @@
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/builders/*'",
"release": "cliff-jumper"
},
"main": "./dist/index.js",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"exports": {
"import": "./dist/index.mjs",
"require": "./dist/index.js",
"require": "./dist/index.cjs",
"types": "./dist/index.d.ts"
},
"directories": {
@ -65,11 +65,13 @@
"@favware/cliff-jumper": "^1.8.5",
"@microsoft/api-extractor": "^7.28.4",
"@types/node": "^16.11.45",
"c8": "^7.11.3",
"c8": "^7.12.0",
"eslint": "^8.20.0",
"prettier": "^2.7.1",
"rollup-plugin-typescript2": "0.32.1",
"tsup": "^6.1.3",
"typescript": "^4.7.4",
"unbuild": "^0.7.4",
"vitest": "^0.18.1"
},
"engines": {

View file

@ -0,0 +1,3 @@
import { createUnbuildConfig } from '../../build.config';
export default createUnbuildConfig();

View file

@ -4,7 +4,7 @@
"description": "Utility data structure used in discord.js",
"scripts": {
"test": "vitest run",
"build": "tsup",
"build": "unbuild",
"lint": "prettier --check . && eslint src __tests__ --ext mjs,js,ts",
"format": "prettier --write . && eslint src __tests__ --ext mjs,js,ts --fix",
"fmt": "yarn format",
@ -13,12 +13,12 @@
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/collection/*'",
"release": "cliff-jumper"
},
"main": "./dist/index.js",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"exports": {
"import": "./dist/index.mjs",
"require": "./dist/index.js",
"require": "./dist/index.cjs",
"types": "./dist/index.d.ts"
},
"directories": {
@ -54,11 +54,13 @@
"@favware/cliff-jumper": "^1.8.5",
"@microsoft/api-extractor": "^7.28.4",
"@types/node": "^16.11.45",
"c8": "^7.11.3",
"c8": "^7.12.0",
"eslint": "^8.20.0",
"prettier": "^2.7.1",
"rollup-plugin-typescript2": "0.32.1",
"tsup": "^6.1.3",
"typescript": "^4.7.4",
"unbuild": "^0.7.4",
"vitest": "^0.18.1"
},
"engines": {

View file

@ -0,0 +1,3 @@
import { createUnbuildConfig } from '../../build.config';
export default createUnbuildConfig({ minify: true, externals: ['package.cjs', 'package.mjs'] });

View file

@ -3,7 +3,7 @@
"version": "0.12.0",
"description": "The docs.json generator for discord.js and its related projects",
"scripts": {
"build": "tsup",
"build": "unbuild",
"lint": "prettier --check . && eslint src --ext mjs,js,ts",
"format": "prettier --write . && eslint src --ext mjs,js,ts --fix",
"fmt": "yarn format",
@ -11,15 +11,7 @@
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/docgen/*'",
"release": "cliff-jumper"
},
"bin": "./dist/index.js",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"exports": {
"import": "./dist/index.mjs",
"require": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"bin": "./dist/index.cjs",
"directories": {
"lib": "src"
},
@ -62,8 +54,10 @@
"@types/node": "^16.11.45",
"eslint": "^8.20.0",
"prettier": "^2.7.1",
"rollup-plugin-typescript2": "0.32.1",
"tsup": "^6.1.3",
"typescript": "^4.7.4"
"typescript": "^4.7.4",
"unbuild": "^0.7.4"
},
"engines": {
"node": ">=16.9.0"

View file

@ -0,0 +1,3 @@
import { createUnbuildConfig } from '../../build.config';
export default createUnbuildConfig({ emitCJS: false, cjsBridge: false });

View file

@ -3,14 +3,14 @@
"version": "0.1.0",
"description": "Lightweight HTTP proxy for Discord's API, brought to you as a container 📦",
"scripts": {
"build": "tsup",
"build": "unbuild",
"lint": "prettier --check . && eslint src --ext mjs,js,ts",
"format": "prettier --write . && eslint src --ext mjs,js,ts --fix",
"fmt": "yarn format",
"prepack": "yarn build && yarn lint",
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/proxy-container/*'"
},
"main": "./dist/index.js",
"main": "./dist/index.mjs",
"type": "module",
"directories": {
"lib": "src"
@ -52,8 +52,10 @@
"@types/node": "^16.11.45",
"eslint": "^8.20.0",
"prettier": "^2.7.1",
"rollup-plugin-typescript2": "0.32.1",
"tsup": "^6.1.3",
"typescript": "^4.7.4"
"typescript": "^4.7.4",
"unbuild": "^0.7.4"
},
"engines": {
"node": ">=16.9.0"

View file

@ -0,0 +1,3 @@
import { createUnbuildConfig } from '../../build.config';
export default createUnbuildConfig();

View file

@ -4,7 +4,7 @@
"description": "Tools for running an HTTP proxy for Discord's API",
"scripts": {
"test": "vitest run",
"build": "tsup",
"build": "unbuild",
"lint": "prettier --check . && eslint src __tests__ --ext mjs,js,ts",
"format": "prettier --write . && eslint src __tests__ --ext mjs,js,ts --fix",
"fmt": "yarn format",
@ -13,12 +13,12 @@
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/proxy/*'",
"release": "cliff-jumper"
},
"main": "./dist/index.js",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"typings": "./dist/index.d.ts",
"exports": {
"import": "./dist/index.mjs",
"require": "./dist/index.js",
"require": "./dist/index.cjs",
"types": "./dist/index.d.ts"
},
"directories": {
@ -64,12 +64,14 @@
"@microsoft/api-extractor": "^7.28.4",
"@types/node": "^16.11.45",
"@types/supertest": "^2.0.12",
"c8": "^7.11.3",
"c8": "^7.12.0",
"eslint": "^8.20.0",
"prettier": "^2.7.1",
"rollup-plugin-typescript2": "0.32.1",
"supertest": "^6.2.4",
"tsup": "^6.1.3",
"typescript": "^4.7.4",
"unbuild": "^0.7.4",
"vitest": "^0.18.1"
},
"engines": {

View file

@ -1,3 +1,3 @@
export * from './handlers/proxyRequests';
export * from './util/responseHelpers';
export { RequestHandler } from './util/util';
export type { RequestHandler } from './util/util';

View file

@ -0,0 +1,3 @@
import { createUnbuildConfig } from '../../build.config';
export default createUnbuildConfig();

View file

@ -4,7 +4,7 @@
"description": "The REST API for discord.js",
"scripts": {
"test": "vitest run",
"build": "tsup",
"build": "unbuild",
"lint": "prettier --check . && eslint src __tests__ --ext mjs,js,ts",
"format": "prettier --write . && eslint src __tests__ --ext mjs,js,ts --fix",
"fmt": "yarn format",
@ -13,12 +13,12 @@
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/rest/*'",
"release": "cliff-jumper"
},
"main": "./dist/index.js",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"typings": "./dist/index.d.ts",
"exports": {
"import": "./dist/index.mjs",
"require": "./dist/index.js",
"require": "./dist/index.cjs",
"types": "./dist/index.d.ts"
},
"directories": {
@ -53,7 +53,7 @@
"homepage": "https://discord.js.org",
"dependencies": {
"@discordjs/collection": "workspace:^",
"@sapphire/async-queue": "^1.3.1",
"@sapphire/async-queue": "^1.3.2",
"@sapphire/snowflake": "^3.2.2",
"discord-api-types": "^0.36.2",
"file-type": "^17.1.2",
@ -65,11 +65,13 @@
"@favware/cliff-jumper": "^1.8.5",
"@microsoft/api-extractor": "^7.28.4",
"@types/node": "^16.11.45",
"c8": "^7.11.3",
"c8": "^7.12.0",
"eslint": "^8.20.0",
"prettier": "^2.7.1",
"rollup-plugin-typescript2": "0.32.1",
"tsup": "^6.1.3",
"typescript": "^4.7.4",
"unbuild": "^0.7.4",
"vitest": "^0.18.1"
},
"engines": {

View file

@ -0,0 +1,3 @@
import { createUnbuildConfig } from '../../build.config';
export default createUnbuildConfig({ minify: true });

View file

@ -5,17 +5,17 @@
"private": true,
"scripts": {
"test": "vitest run",
"build": "tsup",
"build": "unbuild",
"lint": "prettier --check . && eslint src --ext mjs,js,ts",
"format": "prettier --write . && eslint src --ext mjs,js,ts --fix",
"fmt": "yarn format"
},
"main": "./dist/index.js",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"exports": {
"import": "./dist/index.mjs",
"require": "./dist/index.js",
"require": "./dist/index.cjs",
"types": "./dist/index.d.ts"
},
"directories": {
@ -49,11 +49,13 @@
},
"devDependencies": {
"@types/node": "^16.11.45",
"c8": "^7.11.3",
"c8": "^7.12.0",
"eslint": "^8.20.0",
"prettier": "^2.7.1",
"rollup-plugin-typescript2": "0.32.1",
"tsup": "^6.1.3",
"typescript": "^4.7.4",
"unbuild": "^0.7.4",
"vitest": "^0.18.1"
},
"engines": {

View file

@ -0,0 +1,3 @@
import { createUnbuildConfig } from '../../build.config';
export default createUnbuildConfig();

View file

@ -3,7 +3,7 @@
"version": "0.12.0",
"description": "Implementation of the Discord Voice API for node.js",
"scripts": {
"build": "tsup && node scripts/postbuild.mjs",
"build": "unbuild",
"test": "jest --coverage",
"lint": "prettier --check . && eslint src __tests__ --ext mjs,js,ts",
"format": "prettier --write . && eslint src __tests__ --ext mjs,js,ts --fix",
@ -13,12 +13,12 @@
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/voice/*'",
"release": "cliff-jumper"
},
"main": "./dist/index.js",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"typings": "./dist/index.d.ts",
"exports": {
"import": "./dist/index.mjs",
"require": "./dist/index.js",
"require": "./dist/index.cjs",
"types": "./dist/index.d.ts"
},
"directories": {
@ -73,9 +73,11 @@
"jest-websocket-mock": "^2.3.0",
"mock-socket": "^9.1.5",
"prettier": "^2.7.1",
"rollup-plugin-typescript2": "0.32.1",
"tsup": "^6.1.3",
"tweetnacl": "^1.0.3",
"typescript": "^4.7.4"
"typescript": "^4.7.4",
"unbuild": "^0.7.4"
},
"engines": {
"node": ">=16.9.0"

View file

@ -1,19 +1,19 @@
export {
AudioPlayer,
AudioPlayerStatus,
AudioPlayerState,
type AudioPlayerState,
NoSubscriberBehavior,
createAudioPlayer,
AudioPlayerBufferingState,
AudioPlayerIdleState,
AudioPlayerPausedState,
AudioPlayerPlayingState,
CreateAudioPlayerOptions,
type AudioPlayerBufferingState,
type AudioPlayerIdleState,
type AudioPlayerPausedState,
type AudioPlayerPlayingState,
type CreateAudioPlayerOptions,
} from './AudioPlayer';
export { AudioPlayerError } from './AudioPlayerError';
export { AudioResource, CreateAudioResourceOptions, createAudioResource } from './AudioResource';
export { AudioResource, type CreateAudioResourceOptions, createAudioResource } from './AudioResource';
export { PlayerSubscription } from './PlayerSubscription';

View file

@ -5,17 +5,17 @@ export * from './receive';
export {
VoiceConnection,
VoiceConnectionState,
type VoiceConnectionState,
VoiceConnectionStatus,
VoiceConnectionConnectingState,
VoiceConnectionDestroyedState,
VoiceConnectionDisconnectedState,
VoiceConnectionDisconnectedBaseState,
VoiceConnectionDisconnectedOtherState,
VoiceConnectionDisconnectedWebSocketState,
type VoiceConnectionConnectingState,
type VoiceConnectionDestroyedState,
type VoiceConnectionDisconnectedState,
type VoiceConnectionDisconnectedBaseState,
type VoiceConnectionDisconnectedOtherState,
type VoiceConnectionDisconnectedWebSocketState,
VoiceConnectionDisconnectReason,
VoiceConnectionReadyState,
VoiceConnectionSignallingState,
type VoiceConnectionReadyState,
type VoiceConnectionSignallingState,
} from './VoiceConnection';
export { JoinConfig, getVoiceConnection, getVoiceConnections, getGroups } from './DataStore';
export { type JoinConfig, getVoiceConnection, getVoiceConnections, getGroups } from './DataStore';

View file

@ -67,31 +67,31 @@
"@testing-library/dom": "^8.16.0",
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^13.3.0",
"@testing-library/user-event": "^14.2.5",
"@testing-library/user-event": "^14.3.0",
"@types/node": "^16.11.45",
"@types/react-dom": "^18.0.6",
"@types/react-syntax-highlighter": "^15.5.3",
"@typescript-eslint/eslint-plugin": "^5.30.6",
"@typescript-eslint/parser": "^5.30.6",
"@unocss/cli": "^0.44.3",
"@unocss/preset-web-fonts": "^0.44.3",
"@unocss/reset": "^0.44.3",
"@typescript-eslint/eslint-plugin": "^5.30.7",
"@typescript-eslint/parser": "^5.30.7",
"@unocss/cli": "^0.44.5",
"@unocss/preset-web-fonts": "^0.44.5",
"@unocss/reset": "^0.44.5",
"@vitejs/plugin-react": "^2.0.0",
"c8": "^7.11.3",
"concurrently": "^7.2.2",
"cypress": "^10.3.0",
"c8": "^7.12.0",
"concurrently": "^7.3.0",
"cypress": "^10.3.1",
"eslint": "^8.20.0",
"eslint-config-marine": "^9.4.1",
"eslint-config-prettier": "^8.5.0",
"eslint-import-resolver-typescript": "^3.2.7",
"eslint-import-resolver-typescript": "^3.3.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-react": "^7.30.1",
"eslint-plugin-react-hooks": "^4.6.0",
"happy-dom": "^6.0.4",
"msw": "^0.44.1",
"msw": "^0.44.2",
"prettier": "^2.7.1",
"typescript": "^4.7.4",
"unocss": "^0.44.3",
"unocss": "^0.44.5",
"vitest": "^0.18.1"
},
"engines": {

View file

@ -15,12 +15,13 @@
"noUncheckedIndexedAccess": true,
// Modules
"module": "CommonJS",
"module": "ESNext",
"moduleResolution": "node",
"resolveJsonModule": true,
// Emit
"declaration": true,
"declarationMap": true,
"importHelpers": true,
"importsNotUsedAsValues": "error",
"inlineSources": true,

1133
yarn.lock

File diff suppressed because it is too large Load diff