This repository has been archived by the owner on Oct 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: patch tsdx to support multiple entries
Changes copied from jaredpalmer/tsdx#367.
- Loading branch information
1 parent
decc087
commit ce04818
Showing
3 changed files
with
289 additions
and
0 deletions.
There are no files selected for viewing
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,220 @@ | ||
diff --git a/node_modules/tsdx/dist/createBuildConfigs.js b/node_modules/tsdx/dist/createBuildConfigs.js | ||
index 0a6fc49..4bbf936 100644 | ||
--- a/node_modules/tsdx/dist/createBuildConfigs.js | ||
+++ b/node_modules/tsdx/dist/createBuildConfigs.js | ||
@@ -2,7 +2,6 @@ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
const fs = tslib_1.__importStar(require("fs-extra")); | ||
-const jpjs_1 = require("jpjs"); | ||
const constants_1 = require("./constants"); | ||
const createRollupConfig_1 = require("./createRollupConfig"); | ||
// check for custom tsdx.config.js | ||
@@ -15,10 +14,10 @@ if (fs.existsSync(constants_1.paths.appConfig)) { | ||
tsdxConfig = require(constants_1.paths.appConfig); | ||
} | ||
async function createBuildConfigs(opts) { | ||
- const allInputs = jpjs_1.concatAllArray(opts.input.map((input) => createAllFormats(opts, input).map((options, index) => (Object.assign(Object.assign({}, options), { | ||
+ const allInputs = createAllFormats(opts).map((options, index) => (Object.assign(Object.assign({}, options), { | ||
// We want to know if this is the first run for each entryfile | ||
// for certain plugins (e.g. css) | ||
- writeMeta: index === 0 }))))); | ||
+ writeMeta: index === 0 }))); | ||
return await Promise.all(allInputs.map(async (options, index) => { | ||
// pass the full rollup config to tsdx.config.js override | ||
const config = await createRollupConfig_1.createRollupConfig(options, index); | ||
@@ -26,14 +25,26 @@ async function createBuildConfigs(opts) { | ||
})); | ||
} | ||
exports.createBuildConfigs = createBuildConfigs; | ||
-function createAllFormats(opts, input) { | ||
+function createAllFormats(opts) { | ||
+ const sharedOpts = { | ||
+ ...opts, | ||
+ // for multi-entry, we use an input object to specify where to put each | ||
+ // file instead of output.file | ||
+ input: opts.input.reduce((dict, input, index) => { | ||
+ dict[`${opts.output.file[index]}`] = input; | ||
+ return dict; | ||
+ }, {}), | ||
+ // multiple UMD names aren't currently supported for multi-entry | ||
+ // (can't code-split UMD anyway) | ||
+ name: opts.name[0], | ||
+ } | ||
return [ | ||
- opts.format.includes('cjs') && Object.assign(Object.assign({}, opts), { format: 'cjs', env: 'development', input }), | ||
- opts.format.includes('cjs') && Object.assign(Object.assign({}, opts), { format: 'cjs', env: 'production', input }), | ||
- opts.format.includes('esm') && Object.assign(Object.assign({}, opts), { format: 'esm', input }), | ||
- opts.format.includes('umd') && Object.assign(Object.assign({}, opts), { format: 'umd', env: 'development', input }), | ||
- opts.format.includes('umd') && Object.assign(Object.assign({}, opts), { format: 'umd', env: 'production', input }), | ||
- opts.format.includes('system') && Object.assign(Object.assign({}, opts), { format: 'system', env: 'development', input }), | ||
- opts.format.includes('system') && Object.assign(Object.assign({}, opts), { format: 'system', env: 'production', input }), | ||
+ opts.format.includes('cjs') && Object.assign(Object.assign({}, sharedOpts), { format: 'cjs', env: 'development' }), | ||
+ opts.format.includes('cjs') && Object.assign(Object.assign({}, sharedOpts), { format: 'cjs', env: 'production' }), | ||
+ opts.format.includes('esm') && Object.assign(Object.assign({}, sharedOpts), { format: 'esm' }), | ||
+ opts.format.includes('umd') && Object.assign(Object.assign({}, sharedOpts), { format: 'umd', env: 'development' }), | ||
+ opts.format.includes('umd') && Object.assign(Object.assign({}, sharedOpts), { format: 'umd', env: 'production' }), | ||
+ opts.format.includes('system') && Object.assign(Object.assign({}, sharedOpts), { format: 'system', env: 'development' }), | ||
+ opts.format.includes('system') && Object.assign(Object.assign({}, sharedOpts), { format: 'system', env: 'production' }), | ||
].filter(Boolean); | ||
} | ||
diff --git a/node_modules/tsdx/dist/createRollupConfig.js b/node_modules/tsdx/dist/createRollupConfig.js | ||
index d6d9378..0a12c59 100644 | ||
--- a/node_modules/tsdx/dist/createRollupConfig.js | ||
+++ b/node_modules/tsdx/dist/createRollupConfig.js | ||
@@ -23,15 +23,15 @@ async function createRollupConfig(opts, outputNum) { | ||
var _a, _b; | ||
const findAndRecordErrorCodes = await extractErrors_1.extractErrors(Object.assign(Object.assign({}, errorCodeOpts), opts)); | ||
const shouldMinify = opts.minify !== undefined ? opts.minify : opts.env === 'production'; | ||
- const outputName = [ | ||
- `${constants_1.paths.appDist}/${utils_1.safePackageName(opts.name)}`, | ||
- opts.format, | ||
- opts.env, | ||
- shouldMinify ? 'min' : '', | ||
- 'js', | ||
- ] | ||
+ const outputSuffix = [opts.format, opts.env, shouldMinify ? 'min' : '', 'js'] | ||
.filter(Boolean) | ||
.join('.'); | ||
+ let entryFileNames = `[name].${outputSuffix}`; | ||
+ // if there's only one input, uses the package name instead of the filename | ||
+ const inputKeys = Object.keys(opts.input); | ||
+ if (inputKeys.length === 1) { | ||
+ entryFileNames = `${inputKeys[0]}.${outputSuffix}`; | ||
+ } | ||
const tsconfigPath = opts.tsconfig || constants_1.paths.tsconfigJson; | ||
// borrowed from https://github.com/facebook/create-react-app/pull/7248 | ||
const tsconfigJSON = typescript_1.default.readConfigFile(tsconfigPath, typescript_1.default.sys.readFile).config; | ||
@@ -71,8 +71,10 @@ async function createRollupConfig(opts, outputNum) { | ||
}, | ||
// Establish Rollup output | ||
output: { | ||
+ // Set dir to output to | ||
+ dir: constants_1.paths.appDist, | ||
// Set filenames of the consumer's package | ||
- file: outputName, | ||
+ entryFileNames, | ||
// Pass through the file format | ||
format: opts.format, | ||
// Do not let Rollup call Object.freeze() on namespace import objects | ||
diff --git a/node_modules/tsdx/dist/index.js b/node_modules/tsdx/dist/index.js | ||
index d2322e5..184af12 100755 | ||
--- a/node_modules/tsdx/dist/index.js | ||
+++ b/node_modules/tsdx/dist/index.js | ||
@@ -63,6 +63,41 @@ async function getInputs(entries, source) { | ||
((await exports.isDir(utils_1.resolveApp('src'))) && (await jsOrTs('src/index')))) | ||
.map(file => sync_1.default(file))); | ||
} | ||
+function getNamesAndFiles( | ||
+ inputs, | ||
+ name | ||
+) { | ||
+ if (inputs.length === 1) { | ||
+ const singleName = name || appPackageJson.name; | ||
+ return { | ||
+ names: [singleName], | ||
+ files: [utils_1.safePackageName(singleName)], | ||
+ }; | ||
+ } | ||
+ // if multiple entries, each entry should retain its filename | ||
+ const names = []; | ||
+ const files = []; | ||
+ inputs.forEach(input => { | ||
+ // remove leading src/ directory | ||
+ let filename = input; | ||
+ const srcVars = ['src/', './src/']; | ||
+ if (input.startsWith(srcVars[0])) | ||
+ filename = input.substring(srcVars[0].length); | ||
+ else if (input.startsWith(srcVars[1])) | ||
+ filename = input.substring(srcVars[1].length); | ||
+ | ||
+ // remove file extension | ||
+ const noExt = filename | ||
+ .split('.') | ||
+ .slice(0, -1) | ||
+ .join('.'); | ||
+ | ||
+ // UMD name shouldn't contain slashes, replace with __ | ||
+ names.push(noExt.replace('/', '__')); | ||
+ files.push(noExt); | ||
+ }); | ||
+ return { names, files }; | ||
+} | ||
prog | ||
.version(pkg.version) | ||
.command('create <pkg>') | ||
@@ -214,7 +249,11 @@ prog | ||
await cleanDistFolder(); | ||
} | ||
if (opts.format.includes('cjs')) { | ||
- await writeCjsEntryFile(opts.name); | ||
+ await Promise.all( | ||
+ opts.output.file.map(file => | ||
+ writeCjsEntryFile(file, opts.input.length) | ||
+ ) | ||
+ ); | ||
} | ||
let firstTime = true; | ||
let successKiller = null; | ||
@@ -295,8 +334,12 @@ prog | ||
await cleanDistFolder(); | ||
const logger = await createProgressEstimator_1.createProgressEstimator(); | ||
if (opts.format.includes('cjs')) { | ||
- const promise = writeCjsEntryFile(opts.name).catch(logError_1.default); | ||
- logger(promise, 'Creating entry file'); | ||
+ const promise = await Promise.all( | ||
+ opts.output.file.map(file => | ||
+ writeCjsEntryFile(file, opts.input.length).catch(logError_1.default) | ||
+ ) | ||
+ ) | ||
+ logger(promise, `Creating CJS entry file${opts.input.length > 1 ? 's' : ''}`); | ||
} | ||
try { | ||
const promise = asyncro_1.default | ||
@@ -308,10 +351,10 @@ prog | ||
throw e; | ||
}) | ||
.then(async () => { | ||
- await deprecated.moveTypes(); | ||
}); | ||
logger(promise, 'Building modules'); | ||
await promise; | ||
+ await deprecated.moveTypes(); | ||
} | ||
catch (error) { | ||
logError_1.default(error); | ||
@@ -319,18 +362,20 @@ prog | ||
} | ||
}); | ||
async function normalizeOpts(opts) { | ||
- return Object.assign(Object.assign({}, opts), { name: opts.name || appPackageJson.name, input: await getInputs(opts.entry, appPackageJson.source), format: opts.format.split(',').map((format) => { | ||
+ const inputs = await getInputs(opts.entry, appPackageJson.source); | ||
+ const { names, files } = getNamesAndFiles(inputs, opts.name); | ||
+ return Object.assign(Object.assign({}, opts), { name: names, input: inputs, format: opts.format.split(',').map((format) => { | ||
if (format === 'es') { | ||
return 'esm'; | ||
} | ||
return format; | ||
- }) }); | ||
+ }), output: { file: files } }); | ||
} | ||
async function cleanDistFolder() { | ||
await fs.remove(constants_1.paths.appDist); | ||
} | ||
-function writeCjsEntryFile(name) { | ||
- const baseLine = `module.exports = require('./${utils_1.safePackageName(name)}`; | ||
+function writeCjsEntryFile(file, numEntries) { | ||
+ const baseLine = `module.exports = require('./${file}`; | ||
const contents = ` | ||
'use strict' | ||
|
||
@@ -340,7 +385,8 @@ if (process.env.NODE_ENV === 'production') { | ||
${baseLine}.cjs.development.js') | ||
} | ||
`; | ||
- return fs.outputFile(path_1.default.join(constants_1.paths.appDist, 'index.js'), contents); | ||
+ const filename = numEntries === 1 ? 'index.js' : `${file}.js` | ||
+ return fs.outputFile(path_1.default.join(constants_1.paths.appDist, filename), contents); | ||
} | ||
function getAuthorName() { | ||
let author = ''; |
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 |
---|---|---|
|
@@ -2424,6 +2424,11 @@ | |
dependencies: | ||
eslint-visitor-keys "^1.1.0" | ||
|
||
"@yarnpkg/lockfile@^1.1.0": | ||
version "1.1.0" | ||
resolved "https://registry.yarnpkg.com/@yarnpkg/lockfile/-/lockfile-1.1.0.tgz#e77a97fbd345b76d83245edcd17d393b1b41fb31" | ||
integrity sha512-GpSwvyXOcOOlV70vbnzjj4fW5xW/FdUF6nQEt1ENy7m4ZCczi1+/buVUPAqmGfqznsORNFzUMjctTIp8a9tuCQ== | ||
|
||
JSONStream@^1.0.4, JSONStream@^1.2.1: | ||
version "1.3.5" | ||
resolved "https://registry.yarnpkg.com/JSONStream/-/JSONStream-1.3.5.tgz#3208c1f08d3a4d99261ab64f92302bc15e111ca0" | ||
|
@@ -5639,6 +5644,14 @@ find-versions@^3.2.0: | |
dependencies: | ||
semver-regex "^2.0.0" | ||
|
||
find-yarn-workspace-root@^1.2.1: | ||
version "1.2.1" | ||
resolved "https://registry.yarnpkg.com/find-yarn-workspace-root/-/find-yarn-workspace-root-1.2.1.tgz#40eb8e6e7c2502ddfaa2577c176f221422f860db" | ||
integrity sha512-dVtfb0WuQG+8Ag2uWkbG79hOUzEsRrhBzgfn86g2sJPkzmcpGdghbNTfUKGTxymFrY/tLIodDzLoW9nOJ4FY8Q== | ||
dependencies: | ||
fs-extra "^4.0.3" | ||
micromatch "^3.1.4" | ||
|
||
[email protected]: | ||
version "9.2.0" | ||
resolved "https://registry.yarnpkg.com/firebase-admin/-/firebase-admin-9.2.0.tgz#df5176e2d0c5711df6dbf7012320492a703538ea" | ||
|
@@ -5856,6 +5869,24 @@ fs-extra@^0.30.0: | |
path-is-absolute "^1.0.0" | ||
rimraf "^2.2.8" | ||
|
||
fs-extra@^4.0.3: | ||
version "4.0.3" | ||
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-4.0.3.tgz#0d852122e5bc5beb453fb028e9c0c9bf36340c94" | ||
integrity sha512-q6rbdDd1o2mAnQreO7YADIxf/Whx4AHBiRf6d+/cVT8h44ss+lHgxf1FemcqDnQt9X3ct4McHr+JMGlYSsK7Cg== | ||
dependencies: | ||
graceful-fs "^4.1.2" | ||
jsonfile "^4.0.0" | ||
universalify "^0.1.0" | ||
|
||
fs-extra@^7.0.1: | ||
version "7.0.1" | ||
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-7.0.1.tgz#4f189c44aa123b895f722804f55ea23eadc348e9" | ||
integrity sha512-YJDaCJZEnBmcbw13fvdAM9AwNOJwOzrE4pqMqBq5nFiEqXUqHwlK4B+3pUw6JNvfSPtX05xFHtYy/1ni01eGCw== | ||
dependencies: | ||
graceful-fs "^4.1.2" | ||
jsonfile "^4.0.0" | ||
universalify "^0.1.0" | ||
|
||
fs-extra@^9.0.0: | ||
version "9.0.1" | ||
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-9.0.1.tgz#910da0062437ba4c39fedd863f1675ccfefcb9fc" | ||
|
@@ -7898,6 +7929,13 @@ kind-of@^6.0.0, kind-of@^6.0.2, kind-of@^6.0.3: | |
resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-6.0.3.tgz#07c05034a6c349fa06e24fa35aa76db4580ce4dd" | ||
integrity sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw== | ||
|
||
klaw-sync@^6.0.0: | ||
version "6.0.0" | ||
resolved "https://registry.yarnpkg.com/klaw-sync/-/klaw-sync-6.0.0.tgz#1fd2cfd56ebb6250181114f0a581167099c2b28c" | ||
integrity sha512-nIeuVSzdCCs6TDPTqI8w1Yre34sSq7AkZ4B3sfOBbI2CgVSB4Du4aLQijFU2+lhAFCwt9+42Hel6lQNIv6AntQ== | ||
dependencies: | ||
graceful-fs "^4.1.11" | ||
|
||
klaw@^1.0.0: | ||
version "1.3.1" | ||
resolved "https://registry.yarnpkg.com/klaw/-/klaw-1.3.1.tgz#4088433b46b3b1ba259d78785d8e96f73ba02439" | ||
|
@@ -9418,6 +9456,24 @@ pascalcase@^0.1.1: | |
resolved "https://registry.yarnpkg.com/pascalcase/-/pascalcase-0.1.1.tgz#b363e55e8006ca6fe21784d2db22bd15d7917f14" | ||
integrity sha1-s2PlXoAGym/iF4TS2yK9FdeRfxQ= | ||
|
||
[email protected]: | ||
version "6.2.2" | ||
resolved "https://registry.yarnpkg.com/patch-package/-/patch-package-6.2.2.tgz#71d170d650c65c26556f0d0fbbb48d92b6cc5f39" | ||
integrity sha512-YqScVYkVcClUY0v8fF0kWOjDYopzIM8e3bj/RU1DPeEF14+dCGm6UeOYm4jvCyxqIEQ5/eJzmbWfDWnUleFNMg== | ||
dependencies: | ||
"@yarnpkg/lockfile" "^1.1.0" | ||
chalk "^2.4.2" | ||
cross-spawn "^6.0.5" | ||
find-yarn-workspace-root "^1.2.1" | ||
fs-extra "^7.0.1" | ||
is-ci "^2.0.0" | ||
klaw-sync "^6.0.0" | ||
minimist "^1.2.0" | ||
rimraf "^2.6.3" | ||
semver "^5.6.0" | ||
slash "^2.0.0" | ||
tmp "^0.0.33" | ||
|
||
[email protected]: | ||
version "0.0.1" | ||
resolved "https://registry.yarnpkg.com/path-browserify/-/path-browserify-0.0.1.tgz#e6c4ddd7ed3aa27c68a20cc4e50e1a4ee83bbc4a" | ||
|
@@ -9930,6 +9986,11 @@ posthtml@^0.13.1: | |
posthtml-parser "^0.4.2" | ||
posthtml-render "^1.2.2" | ||
|
||
[email protected]: | ||
version "2.1.0" | ||
resolved "https://registry.yarnpkg.com/postinstall-postinstall/-/postinstall-postinstall-2.1.0.tgz#4f7f77441ef539d1512c40bd04c71b06a4704ca3" | ||
integrity sha512-7hQX6ZlZXIoRiWNrbMQaLzUUfH+sSx39u8EJ9HYuDc1kLo9IXKWjM5RSquZN1ad5GnH8CGFM78fsAAQi3OKEEQ== | ||
|
||
prelude-ls@~1.1.2: | ||
version "1.1.2" | ||
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54" | ||
|
@@ -10973,6 +11034,11 @@ sisteransi@^1.0.4: | |
resolved "https://registry.yarnpkg.com/sisteransi/-/sisteransi-1.0.5.tgz#134d681297756437cc05ca01370d3a7a571075ed" | ||
integrity sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg== | ||
|
||
slash@^2.0.0: | ||
version "2.0.0" | ||
resolved "https://registry.yarnpkg.com/slash/-/slash-2.0.0.tgz#de552851a1759df3a8f206535442f5ec4ddeab44" | ||
integrity sha512-ZYKh3Wh2z1PpEXWr0MpSBZ0V6mZHAQfYevttO11c51CaWjGTaadiKZ+wVt1PbMlDV5qhMFslpZCemhwOK7C89A== | ||
|
||
slash@^3.0.0: | ||
version "3.0.0" | ||
resolved "https://registry.yarnpkg.com/slash/-/slash-3.0.0.tgz#6539be870c165adbd5240220dbe361f1bc4d4634" | ||
|