-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8d8ded0
commit fd484bc
Showing
7 changed files
with
239 additions
and
37 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,80 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import nodeResolve from "@rollup/plugin-node-resolve"; | ||
import cjs from "@rollup/plugin-commonjs"; | ||
import multiEntry from "@rollup/plugin-multi-entry"; | ||
import json from "@rollup/plugin-json"; | ||
import * as path from "path"; | ||
|
||
import nodeBuiltins from "builtin-modules"; | ||
|
||
import * as openaiPkg from "./package.json" assert { type: "json" }; | ||
|
||
// #endregion | ||
|
||
export function makeBrowserTestConfig(pkg) { | ||
const module = pkg["module"] ?? "dist-esm/src/index.js"; | ||
const basePath = path.dirname(path.parse(module).dir); | ||
|
||
const config = { | ||
input: path.join(basePath, "test", "**", "*.spec.js"), | ||
output: { | ||
file: `dist-test/index.browser.js`, | ||
format: "umd", | ||
sourcemap: true, | ||
}, | ||
preserveSymlinks: false, | ||
plugins: [ | ||
multiEntry({ exports: false, exclude: ["**/test/**/node/*.js"] }), | ||
nodeResolve({ | ||
mainFields: ["module", "browser"], | ||
preferBuiltins: false, | ||
browser: true, | ||
}), | ||
cjs(), | ||
json(), | ||
], | ||
// Disable tree-shaking of test code. In rollup-plugin-node-resolve@5.0.0, | ||
// rollup started respecting the "sideEffects" field in package.json. Since | ||
// our package.json sets "sideEffects=false", this also applies to test | ||
// code, which causes all tests to be removed by tree-shaking. | ||
treeshake: false, | ||
}; | ||
|
||
return config; | ||
} | ||
|
||
const defaultConfigurationOptions = { | ||
disableBrowserBundle: false, | ||
}; | ||
|
||
export function makeConfig(pkg, options) { | ||
options = { | ||
...defaultConfigurationOptions, | ||
...(options ?? {}), | ||
}; | ||
|
||
const baseConfig = { | ||
// Use the package's module field if it has one | ||
input: pkg["module"] ?? "dist-esm/src/index.js", | ||
external: [ | ||
...nodeBuiltins, | ||
...Object.keys(pkg.dependencies), | ||
...Object.keys(pkg.devDependencies), | ||
], | ||
output: { file: "dist/index.cjs", format: "cjs", sourcemap: true, exports: "named" }, | ||
preserveSymlinks: false, | ||
plugins: [nodeResolve(), cjs(), json()], | ||
}; | ||
|
||
const config = [baseConfig]; | ||
|
||
if (!options.disableBrowserBundle) { | ||
config.push(makeBrowserTestConfig(pkg)); | ||
} | ||
|
||
return config; | ||
} | ||
|
||
export default makeConfig(openaiPkg.default); |
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
Oops, something went wrong.