Skip to content

Commit b4f7201

Browse files
authored
fix: backport package.json ignore on windows (#737)
Closes: #674
1 parent 13ade22 commit b4f7201

7 files changed

+7543
-7
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ jobs:
4242
matrix:
4343
node: [12] # add 14 when we drop support for webpack 4 as fsevents 1 is not compatible with node 14
4444
os: [ubuntu-latest, macos-latest, windows-latest]
45+
fail-fast: false
4546
steps:
4647
- uses: actions/checkout@v1
4748

src/reporter/FilesChange.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,26 @@ interface FilesChange {
77
deletedFiles?: string[];
88
}
99

10+
// we ignore package.json file because of https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/issues/674
11+
const IGNORED_FILES = ['package.json'];
12+
13+
const isIgnoredFile = (file: string) =>
14+
IGNORED_FILES.some(
15+
(ignoredFile) => file.endsWith(`/${ignoredFile}`) || file.endsWith(`\\${ignoredFile}`)
16+
);
17+
1018
const compilerFilesChangeMap = new WeakMap<Compiler, FilesChange>();
1119

1220
function getFilesChange(compiler: Compiler): FilesChange {
13-
return compilerFilesChangeMap.get(compiler) || {};
21+
const { changedFiles = [], deletedFiles = [] } = compilerFilesChangeMap.get(compiler) || {
22+
changedFiles: [],
23+
deletedFiles: [],
24+
};
25+
26+
return {
27+
changedFiles: changedFiles.filter((changedFile) => !isIgnoredFile(changedFile)),
28+
deletedFiles: deletedFiles.filter((deletedFile) => !isIgnoredFile(deletedFile)),
29+
};
1430
}
1531

1632
function updateFilesChange(compiler: Compiler, change: FilesChange): void {

src/watch/InclusiveNodeWatchFileSystem.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import { clearFilesChange, updateFilesChange } from '../reporter';
77
import minimatch from 'minimatch';
88

99
const BUILTIN_IGNORED_DIRS = ['node_modules', '.git', '.yarn', '.pnp'];
10-
// we ignore package.json file because of https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/issues/674
11-
const BUILTIN_IGNORED_FILES = ['package.json'];
1210

1311
function createIsIgnored(
1412
ignored: WatchFileSystemOptions['ignored'] | undefined,
@@ -32,10 +30,9 @@ function createIsIgnored(
3230
excluded.some((excludedPath) => path.startsWith(excludedPath))
3331
);
3432
ignoredFunctions.push((path: string) =>
35-
BUILTIN_IGNORED_DIRS.some((ignoredDir) => path.includes(`/${ignoredDir}/`))
36-
);
37-
ignoredFunctions.push((path: string) =>
38-
BUILTIN_IGNORED_FILES.some((ignoredFile) => path.endsWith(`/${ignoredFile}`))
33+
BUILTIN_IGNORED_DIRS.some(
34+
(ignoredDir) => path.includes(`/${ignoredDir}/`) || path.includes(`\\${ignoredDir}\\`)
35+
)
3936
);
4037

4138
return function isIgnored(path: string) {
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import path, { join } from 'path';
2+
3+
import {
4+
createWebpackDevServerDriver,
5+
WEBPACK_CLI_VERSION,
6+
WEBPACK_DEV_SERVER_VERSION,
7+
} from './sandbox/WebpackDevServerDriver';
8+
import { createSandbox, Sandbox } from './sandbox/Sandbox';
9+
import { readFixture } from './sandbox/Fixture';
10+
import { FORK_TS_CHECKER_WEBPACK_PLUGIN_VERSION } from './sandbox/Plugin';
11+
import { createGenericProcessDriver } from './sandbox/GenericProcessDriver';
12+
13+
describe('Webpack Inclusive Watcher', () => {
14+
let sandbox: Sandbox;
15+
16+
beforeAll(async () => {
17+
sandbox = await createSandbox();
18+
});
19+
20+
beforeEach(async () => {
21+
await sandbox.reset();
22+
});
23+
24+
afterAll(async () => {
25+
await sandbox.cleanup();
26+
});
27+
28+
it.each([{ async: false }, { async: true }])(
29+
'ignores package.json change for %p',
30+
async ({ async }) => {
31+
await sandbox.load([
32+
await readFixture(path.join(__dirname, 'fixtures/environment/typescript-basic.fixture'), {
33+
FORK_TS_CHECKER_WEBPACK_PLUGIN_VERSION: JSON.stringify(
34+
FORK_TS_CHECKER_WEBPACK_PLUGIN_VERSION
35+
),
36+
TS_LOADER_VERSION: JSON.stringify('^7.0.0'),
37+
TYPESCRIPT_VERSION: JSON.stringify('4.6.3'),
38+
WEBPACK_VERSION: JSON.stringify('^5.0.0'),
39+
WEBPACK_CLI_VERSION: JSON.stringify(WEBPACK_CLI_VERSION),
40+
WEBPACK_DEV_SERVER_VERSION: JSON.stringify(WEBPACK_DEV_SERVER_VERSION),
41+
ASYNC: JSON.stringify(async),
42+
}),
43+
await readFixture(join(__dirname, 'fixtures/implementation/typescript-basic.fixture')),
44+
await readFixture(
45+
path.join(__dirname, 'fixtures/implementation/typescript-package.fixture')
46+
),
47+
]);
48+
49+
// add import to typescript-nested-project project
50+
await sandbox.patch(
51+
'src/index.ts',
52+
"import { getUserName } from './model/User';",
53+
[
54+
"import { getUserName } from './model/User';",
55+
'import { sayHello } from "../package";',
56+
'',
57+
"sayHello('World');",
58+
].join('\n')
59+
);
60+
61+
// start webpack dev server
62+
const process = sandbox.spawn('npm run webpack-dev-server');
63+
const baseDriver = createGenericProcessDriver(process);
64+
const webpackDriver = createWebpackDevServerDriver(process, async);
65+
66+
await webpackDriver.waitForNoErrors();
67+
68+
// update nested package.json file
69+
await sandbox.patch('package/package.json', '"1.0.0"', '"1.0.1"');
70+
71+
// wait for 5 seconds and fail if there is Debug Failure. in the console output
72+
await expect(() =>
73+
baseDriver.waitForStderrIncludes('Error: Debug Failure.', 5000)
74+
).rejects.toEqual(
75+
new Error('Exceeded time on waiting for "Error: Debug Failure." to appear in the stderr.')
76+
);
77+
78+
await webpackDriver.waitForNoErrors();
79+
}
80+
);
81+
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/// package/package.json
2+
{
3+
"name": "typescript-nested-project",
4+
"version": "1.0.0",
5+
"license": "MIT",
6+
"main": "./index.js",
7+
"types": "./index.d.ts",
8+
"files": [
9+
"./index.js"
10+
]
11+
}
12+
13+
/// package/index.d.ts
14+
export declare function sayHello(who: string): string;
15+
16+
/// package/index.js
17+
"use strict";
18+
exports.__esModule = true;
19+
exports.sayHello = void 0;
20+
function sayHello(who) {
21+
return 'Hello ' + who + '!';
22+
}
23+
exports.sayHello = sayHello;

0 commit comments

Comments
 (0)