Skip to content

Commit 67e5952

Browse files
committed
adjust prepack.ts to distinguish between packages with/-out bundles
1 parent 14b7962 commit 67e5952

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

scripts/prepack.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,23 @@ import * as fse from 'fs-extra';
1111
import * as path from 'path';
1212

1313
const NPM_BUILD_DIR = 'build/npm';
14+
const BUILD_DIR = 'build';
15+
1416
const ASSETS = ['README.md', 'LICENSE', 'package.json', '.npmignore'];
1517
const ENTRY_POINTS = ['main', 'module', 'types'];
1618

19+
const packageWithBundles = !process.argv.includes('-noBundles');
20+
const buildDir = packageWithBundles ? NPM_BUILD_DIR : BUILD_DIR;
21+
1722
// check if build dir exists
1823
try {
19-
if (!fs.existsSync(path.resolve(NPM_BUILD_DIR))) {
20-
console.error(`Directory ${NPM_BUILD_DIR} DOES NOT exist`);
24+
if (!fs.existsSync(path.resolve(buildDir))) {
25+
console.error(`Directory ${buildDir} DOES NOT exist`);
2126
console.error("This script should only be executed after you've run `yarn build`.");
2227
process.exit(1);
2328
}
2429
} catch (error) {
25-
console.error(`Error while looking up directory ${NPM_BUILD_DIR}`);
30+
console.error(`Error while looking up directory ${buildDir}`);
2631
process.exit(1);
2732
}
2833

@@ -34,9 +39,9 @@ ASSETS.forEach(asset => {
3439
console.error(`Asset ${asset} does not exist.`);
3540
process.exit(1);
3641
}
37-
fs.copyFileSync(assetPath, path.resolve(NPM_BUILD_DIR, asset));
42+
fs.copyFileSync(assetPath, path.resolve(buildDir, asset));
3843
} catch (error) {
39-
console.error(`Error while copying ${asset} to ${NPM_BUILD_DIR}`);
44+
console.error(`Error while copying ${asset} to ${buildDir}`);
4045
process.exit(1);
4146
}
4247
});
@@ -45,28 +50,30 @@ ASSETS.forEach(asset => {
4550
// copy CDN bundles into npm dir to temporarily keep bundles in npm tarball
4651
// inside the tarball, they are located in `build/`
4752
// for now, copy it by default, unless explicitly forbidden via an command line arg
48-
const tmpCopyBundles = !process.argv.includes('-skipBundleCopy');
53+
const tmpCopyBundles = packageWithBundles && !process.argv.includes('-skipBundleCopy');
4954
if (tmpCopyBundles) {
50-
const npmTmpBundlesPath = path.resolve(NPM_BUILD_DIR, 'build');
55+
const npmTmpBundlesPath = path.resolve(buildDir, 'build');
5156
const cdnBundlesPath = path.resolve('build', 'bundles');
5257
try {
5358
if (!fs.existsSync(npmTmpBundlesPath)) {
5459
fs.mkdirSync(npmTmpBundlesPath);
5560
}
5661
void fse.copy(cdnBundlesPath, npmTmpBundlesPath);
5762
} catch (error) {
58-
console.error(`Error while tmp copying CDN bundles to ${NPM_BUILD_DIR}`);
63+
console.error(`Error while tmp copying CDN bundles to ${buildDir}`);
5964
process.exit(1);
6065
}
6166
}
67+
// end remove
68+
6269
// package.json modifications
63-
const packageJsonPath = path.resolve(NPM_BUILD_DIR, 'package.json');
70+
const packageJsonPath = path.resolve(buildDir, 'package.json');
6471
// eslint-disable-next-line @typescript-eslint/no-var-requires
6572
const pkgJson: { [key: string]: unknown } = require(packageJsonPath);
6673

6774
// modify entry points to point to correct paths (i.e. strip out the build directory)
6875
ENTRY_POINTS.filter(entryPoint => pkgJson[entryPoint]).forEach(entryPoint => {
69-
pkgJson[entryPoint] = (pkgJson[entryPoint] as string).replace(`${NPM_BUILD_DIR}/`, '');
76+
pkgJson[entryPoint] = (pkgJson[entryPoint] as string).replace(`${buildDir}/`, '');
7077
});
7178

7279
delete pkgJson.scripts;

0 commit comments

Comments
 (0)