Skip to content

Commit 3aa5ee3

Browse files
authored
- Fix: Ensure paths work on Windows (#84)
- Enhancement: Add logging upon missing file or package - Testing: Tighten/Loosen size expectations for testing on Windows - Testing: Check Windows - Testing: Run tests serially to avoid errors due to overlapping package/file changes - npm: Update `babel/runtime`, pacote, terser deps. and devDeps
1 parent 6191b09 commit 3aa5ee3

File tree

5 files changed

+922
-715
lines changed

5 files changed

+922
-715
lines changed

.github/workflows/nodejs.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ on:
1111

1212
jobs:
1313
build:
14-
runs-on: ubuntu-latest
14+
runs-on: ${{ matrix.os }}
1515

1616
strategy:
1717
matrix:
18+
os: [windows-latest, ubuntu-latest]
1819
node-version: [10.x, 12.x, 14.x]
1920

2021
steps:

package.json

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"typings": "./index.d.ts",
1616
"scripts": {
1717
"lint": "eslint .",
18-
"test": "nyc ava test/index.test.js",
18+
"test": "nyc ava --serial test/index.test.js",
1919
"remove-dist": "rimraf dist/*",
2020
"pretest": "rollup -c",
2121
"prepare": "npm run remove-dist && npm run test"
@@ -38,34 +38,34 @@
3838
},
3939
"homepage": "https://github.com/ritz078/rollup-plugin-filesize#readme",
4040
"dependencies": {
41-
"@babel/runtime": "^7.9.6",
41+
"@babel/runtime": "^7.10.3",
4242
"boxen": "^4.2.0",
4343
"brotli-size": "4.0.0",
4444
"colors": "^1.4.0",
4545
"filesize": "^6.1.0",
4646
"gzip-size": "^5.1.1",
47-
"pacote": "^11.1.6",
48-
"terser": "^4.6.12"
47+
"pacote": "^11.1.10",
48+
"terser": "^4.8.0"
4949
},
5050
"devDependencies": {
51-
"@babel/core": "^7.9.0",
52-
"@babel/plugin-syntax-import-meta": "^7.8.3",
53-
"@babel/plugin-transform-runtime": "^7.9.6",
54-
"@babel/preset-env": "^7.9.5",
55-
"@babel/register": "^7.9.0",
56-
"@rollup/plugin-babel": "^5.0.0",
57-
"@rollup/plugin-json": "^4.0.3",
58-
"ava": "^3.8.1",
51+
"@babel/core": "^7.10.3",
52+
"@babel/plugin-syntax-import-meta": "^7.10.1",
53+
"@babel/plugin-transform-runtime": "^7.10.3",
54+
"@babel/preset-env": "^7.10.3",
55+
"@babel/register": "^7.10.3",
56+
"@rollup/plugin-babel": "^5.0.4",
57+
"@rollup/plugin-json": "^4.1.0",
58+
"ava": "^3.9.0",
5959
"babel-eslint": "^10.1.0",
6060
"babel-register": "^6.26.0",
61-
"eslint": "^6.8.0",
61+
"eslint": "^7.3.1",
6262
"eslint-config-prettier": "^6.11.0",
63-
"eslint-plugin-prettier": "^3.1.3",
63+
"eslint-plugin-prettier": "^3.1.4",
6464
"esm": "^3.2.25",
65-
"nyc": "^15.0.1",
65+
"nyc": "^15.1.0",
6666
"prettier": "^2.0.5",
6767
"rimraf": "^3.0.2",
68-
"rollup": "^2.7.3"
68+
"rollup": "^2.18.1"
6969
},
7070
"ava": {
7171
"require": [

src/index.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,14 @@ function fixWindowsPath(path) {
2424
// to remove slash instead
2525
// "file://" +
2626
const thisDirectory = fixWindowsPath(
27-
dirname(new URL(import.meta.url).pathname)
27+
dirname(
28+
new URL(
29+
// `import.meta.url` is giving backslashes in Windows currently
30+
// (at least in how it is compiled to CJS) which makes for an
31+
// invalid URL
32+
import.meta.url.replace(/\\/g, "/")
33+
).pathname
34+
)
2835
);
2936

3037
export default function filesize(options = {}, env) {
@@ -46,9 +53,7 @@ export default function filesize(options = {}, env) {
4653
if (showBeforeSizes !== "none") {
4754
let file = outputOptions.file || outputOptions.dest;
4855
if (showBeforeSizes !== "build") {
49-
const { name } = await import(
50-
fixWindowsPath(join(process.cwd(), "./package.json"))
51-
);
56+
const { name } = await import(join(process.cwd(), "./package.json"));
5257
try {
5358
const output = join(thisDirectory, "../.cache");
5459

@@ -63,6 +68,7 @@ export default function filesize(options = {}, env) {
6368
file = pathResolve(output, file);
6469
} catch (err) {
6570
// Package might not exist
71+
console.log(`Package, "${name}", was not found.`);
6672
file = null;
6773
}
6874
}
@@ -71,6 +77,7 @@ export default function filesize(options = {}, env) {
7177
try {
7278
codeBefore = await readFile(file, "utf8");
7379
} catch (err) {
80+
console.log(`File, "${file}", was not found.`);
7481
// File might not exist
7582
}
7683
}
@@ -139,9 +146,9 @@ export default function filesize(options = {}, env) {
139146
if (typeof reporter === "string") {
140147
let p;
141148
if (reporter === "boxen") {
142-
p = import(thisDirectory + "/reporters/boxen.js");
149+
p = import(join(thisDirectory, "/reporters/boxen.js"));
143150
} else {
144-
p = import(fixWindowsPath(pathResolve(process.cwd(), reporter)));
151+
p = import(pathResolve(process.cwd(), reporter));
145152
}
146153
reporter = (await p).default;
147154
}

test/index.test.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,9 @@ test('fileSize should apply `showBeforeSizes` option as "build"', async (t) => {
218218
t.regex(val, /in last build/);
219219
if (colors.supportsColor()) {
220220
// eslint-disable-next-line no-control-regex
221-
t.regex(val, /\(was \u001b\[33m[\d.]+ K?B/);
221+
t.regex(val, /\(was \u001b\[33m[\d.]+ KB/);
222222
} else {
223-
t.regex(val, /\(was [\d.]+ K?B/);
223+
t.regex(val, /\(was [\d.]+ KB/);
224224
}
225225
});
226226

@@ -350,9 +350,9 @@ test("fileSize should show before Brotli size when configured", async (t) => {
350350

351351
if (colors.supportsColor()) {
352352
// eslint-disable-next-line no-control-regex
353-
t.regex(val, /\(was \u001b\[33m25 B/);
353+
t.regex(val, /\(was \u001b\[33m[\d.]+ B/);
354354
} else {
355-
t.regex(val, /\(was 25 B/);
355+
t.regex(val, /\(was [\d.]+ B/);
356356
}
357357

358358
getLoggingData = filesize(
@@ -370,9 +370,9 @@ test("fileSize should show before Brotli size when configured", async (t) => {
370370
t.notRegex(val, /Gzipped Size/);
371371
if (colors.supportsColor()) {
372372
// eslint-disable-next-line no-control-regex
373-
t.regex(val, /\(was \u001b\[33m25 B/);
373+
t.regex(val, /\(was \u001b\[33m[\d.]+ B/);
374374
} else {
375-
t.regex(val, /\(was 25 B/);
375+
t.regex(val, /\(was [\d.]+ B/);
376376
}
377377

378378
getLoggingData = filesize(
@@ -391,9 +391,9 @@ test("fileSize should show before Brotli size when configured", async (t) => {
391391

392392
if (colors.supportsColor()) {
393393
// eslint-disable-next-line no-control-regex
394-
t.regex(val, /\(was \u001b\[33m25 B/);
394+
t.regex(val, /\(was \u001b\[33m[\d.]+ B/);
395395
} else {
396-
t.regex(val, /\(was 25 B/);
396+
t.regex(val, /\(was [\d.]+ B/);
397397
}
398398

399399
getLoggingData = filesize(
@@ -411,9 +411,9 @@ test("fileSize should show before Brotli size when configured", async (t) => {
411411
t.regex(val, /Gzipped Size/);
412412
if (colors.supportsColor()) {
413413
// eslint-disable-next-line no-control-regex
414-
t.regex(val, /\(was \u001b\[33m25 B/);
414+
t.regex(val, /\(was \u001b\[33m[\d.]+ B/);
415415
} else {
416-
t.regex(val, /\(was 25 B/);
416+
t.regex(val, /\(was [\d.]+ B/);
417417
}
418418
});
419419

0 commit comments

Comments
 (0)