Skip to content

Commit ba31cb8

Browse files
authored
Move to upath, honor swDest subdirs (#2140)
1 parent b0825d7 commit ba31cb8

30 files changed

+272
-440
lines changed

Diff for: packages/workbox-build/package-lock.json

-229
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: packages/workbox-build/src/entry-points/inject-manifest.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
const assert = require('assert');
1010
const fse = require('fs-extra');
11-
const path = require('path');
11+
const upath = require('upath');
1212

1313
const errors = require('../lib/errors');
1414
const escapeRegexp = require('../lib/escape-regexp');
@@ -40,7 +40,7 @@ const validate = require('./options/validate');
4040
async function injectManifest(config) {
4141
const options = validate(config, injectManifestSchema);
4242

43-
if (path.resolve(config.swSrc) === path.resolve(config.swDest)) {
43+
if (upath.resolve(config.swSrc) === upath.resolve(config.swDest)) {
4444
throw new Error(errors['same-src-and-dest']);
4545
}
4646

@@ -65,7 +65,7 @@ async function injectManifest(config) {
6565
swFileContents = swFileContents.replace(globalRegexp, entriesString);
6666

6767
try {
68-
await fse.mkdirp(path.dirname(options.swDest));
68+
await fse.mkdirp(upath.dirname(options.swDest));
6969
} catch (error) {
7070
throw new Error(errors['unable-to-make-injection-directory'] +
7171
` '${error.message}'`);

Diff for: packages/workbox-build/src/lib/bundle.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const {terser} = require('rollup-plugin-terser');
1111
const {writeFile} = require('fs-extra');
1212
const babel = require('rollup-plugin-babel');
1313
const omt = require('rollup-plugin-off-main-thread');
14-
const path = require('path');
14+
const upath = require('upath');
1515
const presetEnv = require('@babel/preset-env');
1616
const replace = require('rollup-plugin-replace');
1717
const resolve = require('rollup-plugin-node-resolve');
@@ -27,7 +27,9 @@ module.exports = async ({
2727
}) => {
2828
// We need to write this to the "real" file system, as Rollup won't read from
2929
// a custom file system.
30-
const temporaryFile = tempy.file({name: path.basename(swDest)});
30+
const {dir, base} = upath.parse(swDest);
31+
32+
const temporaryFile = tempy.file({name: base});
3133
await writeFile(temporaryFile, unbundledCode);
3234

3335
const plugins = [
@@ -107,5 +109,13 @@ module.exports = async ({
107109
}
108110
}
109111

110-
return files;
112+
// Make sure that if there was a directory portion included in swDest, it's
113+
// preprended to all of the generated files.
114+
return files.map((file) => {
115+
file.name = upath.format({
116+
dir,
117+
base: file.name,
118+
});
119+
return file;
120+
});
111121
};

Diff for: packages/workbox-build/src/lib/copy-workbox-libraries.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
const fse = require('fs-extra');
10-
const path = require('path');
10+
const upath = require('upath');
1111
const errors = require('./errors');
1212

1313

@@ -43,7 +43,7 @@ module.exports = async (destDirectory) => {
4343
// pkg.version whenever one of the dependent libraries gets bumped, and we
4444
// care about versioning the dependent libraries.
4545
const workboxDirectoryName = `workbox-v${thisPkg.version}`;
46-
const workboxDirectoryPath = path.join(destDirectory, workboxDirectoryName);
46+
const workboxDirectoryPath = upath.join(destDirectory, workboxDirectoryName);
4747
await fse.ensureDir(workboxDirectoryPath);
4848

4949
const copyPromises = [];
@@ -53,10 +53,10 @@ module.exports = async (destDirectory) => {
5353
for (const library of librariesToCopy) {
5454
// Get the path to the package on the user's filesystem by require-ing
5555
// the package's `package.json` file via the node resolution algorithm.
56-
const libraryPath = path.dirname(
56+
const libraryPath = upath.dirname(
5757
require.resolve(`${library}/package.json`));
5858

59-
const buildPath = path.join(libraryPath, BUILD_DIR);
59+
const buildPath = upath.join(libraryPath, BUILD_DIR);
6060

6161
// fse.copy() copies all the files in a directory, not the directory itself.
6262
// See https://github.com/jprichardson/node-fs-extra/blob/master/docs/copy.md#copysrc-dest-options-callback

Diff for: packages/workbox-build/src/lib/get-file-details.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
const glob = require('glob');
10-
const path = require('path');
10+
const upath = require('upath');
1111

1212
const errors = require('./errors');
1313
const getFileSize = require('./get-file-size');
@@ -40,15 +40,15 @@ module.exports = ({
4040
}
4141

4242
const fileDetails = globbedFiles.map((file) => {
43-
const fullPath = path.join(globDirectory, file);
43+
const fullPath = upath.join(globDirectory, file);
4444
const fileSize = getFileSize(fullPath);
4545
if (fileSize === null) {
4646
return null;
4747
}
4848

4949
const fileHash = getFileHash(fullPath);
5050
return {
51-
file: `${path.relative(globDirectory, fullPath)}`,
51+
file: `${upath.relative(globDirectory, fullPath)}`,
5252
hash: fileHash,
5353
size: fileSize,
5454
};

Diff for: packages/workbox-build/src/lib/get-file-manifest-entries.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
const assert = require('assert');
10-
const path = require('path');
10+
const upath = require('upath');
1111

1212
const errors = require('./errors');
1313
const transformManifest = require('./transform-manifest');
@@ -38,7 +38,7 @@ module.exports = async ({
3838
if (globDirectory) {
3939
if (swDest) {
4040
// Ensure that we ignore the SW file we're eventually writing to disk.
41-
globIgnores.push(`**/${path.basename(swDest)}`);
41+
globIgnores.push(`**/${upath.basename(swDest)}`);
4242
}
4343

4444
try {

0 commit comments

Comments
 (0)