Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: refactor build system (#8324)
- Loading branch information
Showing
27 changed files
with
1,116 additions
and
334 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
.yarn/patches/rollup-plugin-typescript2-npm-0.32.1-b5887420f2.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}, | ||
}, | ||
}), | ||
); | ||
} | ||
}, | ||
}, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { createUnbuildConfig } from '../../build.config'; | ||
|
||
export default createUnbuildConfig({ minify: true }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { createUnbuildConfig } from '../../build.config'; | ||
|
||
export default createUnbuildConfig(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { createUnbuildConfig } from '../../build.config'; | ||
|
||
export default createUnbuildConfig(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { createUnbuildConfig } from '../../build.config'; | ||
|
||
export default createUnbuildConfig({ minify: true, externals: ['package.cjs', 'package.mjs'] }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { createUnbuildConfig } from '../../build.config'; | ||
|
||
export default createUnbuildConfig({ emitCJS: false, cjsBridge: false }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { createUnbuildConfig } from '../../build.config'; | ||
|
||
export default createUnbuildConfig(); |
Oops, something went wrong.
3b0197b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
discord-js – ./
discord-js-discordjs.vercel.app
discord-js-git-main-discordjs.vercel.app
discord-js-number-one.vercel.app
discordjs.dev
www.discordjs.dev