Skip to content

Commit

Permalink
- Fix: Ensure paths work on Windows (#84)
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
brettz9 committed Jun 30, 2020
1 parent 6191b09 commit 3aa5ee3
Show file tree
Hide file tree
Showing 5 changed files with 922 additions and 715 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ on:

jobs:
build:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [windows-latest, ubuntu-latest]
node-version: [10.x, 12.x, 14.x]

steps:
Expand Down
32 changes: 16 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"typings": "./index.d.ts",
"scripts": {
"lint": "eslint .",
"test": "nyc ava test/index.test.js",
"test": "nyc ava --serial test/index.test.js",
"remove-dist": "rimraf dist/*",
"pretest": "rollup -c",
"prepare": "npm run remove-dist && npm run test"
Expand All @@ -38,34 +38,34 @@
},
"homepage": "https://github.com/ritz078/rollup-plugin-filesize#readme",
"dependencies": {
"@babel/runtime": "^7.9.6",
"@babel/runtime": "^7.10.3",
"boxen": "^4.2.0",
"brotli-size": "4.0.0",
"colors": "^1.4.0",
"filesize": "^6.1.0",
"gzip-size": "^5.1.1",
"pacote": "^11.1.6",
"terser": "^4.6.12"
"pacote": "^11.1.10",
"terser": "^4.8.0"
},
"devDependencies": {
"@babel/core": "^7.9.0",
"@babel/plugin-syntax-import-meta": "^7.8.3",
"@babel/plugin-transform-runtime": "^7.9.6",
"@babel/preset-env": "^7.9.5",
"@babel/register": "^7.9.0",
"@rollup/plugin-babel": "^5.0.0",
"@rollup/plugin-json": "^4.0.3",
"ava": "^3.8.1",
"@babel/core": "^7.10.3",
"@babel/plugin-syntax-import-meta": "^7.10.1",
"@babel/plugin-transform-runtime": "^7.10.3",
"@babel/preset-env": "^7.10.3",
"@babel/register": "^7.10.3",
"@rollup/plugin-babel": "^5.0.4",
"@rollup/plugin-json": "^4.1.0",
"ava": "^3.9.0",
"babel-eslint": "^10.1.0",
"babel-register": "^6.26.0",
"eslint": "^6.8.0",
"eslint": "^7.3.1",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-prettier": "^3.1.3",
"eslint-plugin-prettier": "^3.1.4",
"esm": "^3.2.25",
"nyc": "^15.0.1",
"nyc": "^15.1.0",
"prettier": "^2.0.5",
"rimraf": "^3.0.2",
"rollup": "^2.7.3"
"rollup": "^2.18.1"
},
"ava": {
"require": [
Expand Down
19 changes: 13 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ function fixWindowsPath(path) {
// to remove slash instead
// "file://" +
const thisDirectory = fixWindowsPath(
dirname(new URL(import.meta.url).pathname)
dirname(
new URL(
// `import.meta.url` is giving backslashes in Windows currently
// (at least in how it is compiled to CJS) which makes for an
// invalid URL
import.meta.url.replace(/\\/g, "/")
).pathname
)
);

export default function filesize(options = {}, env) {
Expand All @@ -46,9 +53,7 @@ export default function filesize(options = {}, env) {
if (showBeforeSizes !== "none") {
let file = outputOptions.file || outputOptions.dest;
if (showBeforeSizes !== "build") {
const { name } = await import(
fixWindowsPath(join(process.cwd(), "./package.json"))
);
const { name } = await import(join(process.cwd(), "./package.json"));
try {
const output = join(thisDirectory, "../.cache");

Expand All @@ -63,6 +68,7 @@ export default function filesize(options = {}, env) {
file = pathResolve(output, file);
} catch (err) {
// Package might not exist
console.log(`Package, "${name}", was not found.`);
file = null;
}
}
Expand All @@ -71,6 +77,7 @@ export default function filesize(options = {}, env) {
try {
codeBefore = await readFile(file, "utf8");
} catch (err) {
console.log(`File, "${file}", was not found.`);
// File might not exist
}
}
Expand Down Expand Up @@ -139,9 +146,9 @@ export default function filesize(options = {}, env) {
if (typeof reporter === "string") {
let p;
if (reporter === "boxen") {
p = import(thisDirectory + "/reporters/boxen.js");
p = import(join(thisDirectory, "/reporters/boxen.js"));
} else {
p = import(fixWindowsPath(pathResolve(process.cwd(), reporter)));
p = import(pathResolve(process.cwd(), reporter));
}
reporter = (await p).default;
}
Expand Down
20 changes: 10 additions & 10 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,9 @@ test('fileSize should apply `showBeforeSizes` option as "build"', async (t) => {
t.regex(val, /in last build/);
if (colors.supportsColor()) {
// eslint-disable-next-line no-control-regex
t.regex(val, /\(was \u001b\[33m[\d.]+ K?B/);
t.regex(val, /\(was \u001b\[33m[\d.]+ KB/);
} else {
t.regex(val, /\(was [\d.]+ K?B/);
t.regex(val, /\(was [\d.]+ KB/);
}
});

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

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

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

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

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

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

Expand Down
Loading

0 comments on commit 3aa5ee3

Please sign in to comment.