Skip to content

Commit

Permalink
fix: backport package.json ignore on windows (#737)
Browse files Browse the repository at this point in the history
Closes: #674
  • Loading branch information
piotr-oles committed Apr 26, 2022
1 parent 13ade22 commit b4f7201
Show file tree
Hide file tree
Showing 7 changed files with 7,543 additions and 7 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ jobs:
matrix:
node: [12] # add 14 when we drop support for webpack 4 as fsevents 1 is not compatible with node 14
os: [ubuntu-latest, macos-latest, windows-latest]
fail-fast: false
steps:
- uses: actions/checkout@v1

Expand Down
18 changes: 17 additions & 1 deletion src/reporter/FilesChange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,26 @@ interface FilesChange {
deletedFiles?: string[];
}

// we ignore package.json file because of https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/issues/674
const IGNORED_FILES = ['package.json'];

const isIgnoredFile = (file: string) =>
IGNORED_FILES.some(
(ignoredFile) => file.endsWith(`/${ignoredFile}`) || file.endsWith(`\\${ignoredFile}`)
);

const compilerFilesChangeMap = new WeakMap<Compiler, FilesChange>();

function getFilesChange(compiler: Compiler): FilesChange {
return compilerFilesChangeMap.get(compiler) || {};
const { changedFiles = [], deletedFiles = [] } = compilerFilesChangeMap.get(compiler) || {
changedFiles: [],
deletedFiles: [],
};

return {
changedFiles: changedFiles.filter((changedFile) => !isIgnoredFile(changedFile)),
deletedFiles: deletedFiles.filter((deletedFile) => !isIgnoredFile(deletedFile)),
};
}

function updateFilesChange(compiler: Compiler, change: FilesChange): void {
Expand Down
9 changes: 3 additions & 6 deletions src/watch/InclusiveNodeWatchFileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import { clearFilesChange, updateFilesChange } from '../reporter';
import minimatch from 'minimatch';

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

function createIsIgnored(
ignored: WatchFileSystemOptions['ignored'] | undefined,
Expand All @@ -32,10 +30,9 @@ function createIsIgnored(
excluded.some((excludedPath) => path.startsWith(excludedPath))
);
ignoredFunctions.push((path: string) =>
BUILTIN_IGNORED_DIRS.some((ignoredDir) => path.includes(`/${ignoredDir}/`))
);
ignoredFunctions.push((path: string) =>
BUILTIN_IGNORED_FILES.some((ignoredFile) => path.endsWith(`/${ignoredFile}`))
BUILTIN_IGNORED_DIRS.some(
(ignoredDir) => path.includes(`/${ignoredDir}/`) || path.includes(`\\${ignoredDir}\\`)
)
);

return function isIgnored(path: string) {
Expand Down
81 changes: 81 additions & 0 deletions test/e2e/WebpackInclusiveWatcher.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import path, { join } from 'path';

import {
createWebpackDevServerDriver,
WEBPACK_CLI_VERSION,
WEBPACK_DEV_SERVER_VERSION,
} from './sandbox/WebpackDevServerDriver';
import { createSandbox, Sandbox } from './sandbox/Sandbox';
import { readFixture } from './sandbox/Fixture';
import { FORK_TS_CHECKER_WEBPACK_PLUGIN_VERSION } from './sandbox/Plugin';
import { createGenericProcessDriver } from './sandbox/GenericProcessDriver';

describe('Webpack Inclusive Watcher', () => {
let sandbox: Sandbox;

beforeAll(async () => {
sandbox = await createSandbox();
});

beforeEach(async () => {
await sandbox.reset();
});

afterAll(async () => {
await sandbox.cleanup();
});

it.each([{ async: false }, { async: true }])(
'ignores package.json change for %p',
async ({ async }) => {
await sandbox.load([
await readFixture(path.join(__dirname, 'fixtures/environment/typescript-basic.fixture'), {
FORK_TS_CHECKER_WEBPACK_PLUGIN_VERSION: JSON.stringify(
FORK_TS_CHECKER_WEBPACK_PLUGIN_VERSION
),
TS_LOADER_VERSION: JSON.stringify('^7.0.0'),
TYPESCRIPT_VERSION: JSON.stringify('4.6.3'),
WEBPACK_VERSION: JSON.stringify('^5.0.0'),
WEBPACK_CLI_VERSION: JSON.stringify(WEBPACK_CLI_VERSION),
WEBPACK_DEV_SERVER_VERSION: JSON.stringify(WEBPACK_DEV_SERVER_VERSION),
ASYNC: JSON.stringify(async),
}),
await readFixture(join(__dirname, 'fixtures/implementation/typescript-basic.fixture')),
await readFixture(
path.join(__dirname, 'fixtures/implementation/typescript-package.fixture')
),
]);

// add import to typescript-nested-project project
await sandbox.patch(
'src/index.ts',
"import { getUserName } from './model/User';",
[
"import { getUserName } from './model/User';",
'import { sayHello } from "../package";',
'',
"sayHello('World');",
].join('\n')
);

// start webpack dev server
const process = sandbox.spawn('npm run webpack-dev-server');
const baseDriver = createGenericProcessDriver(process);
const webpackDriver = createWebpackDevServerDriver(process, async);

await webpackDriver.waitForNoErrors();

// update nested package.json file
await sandbox.patch('package/package.json', '"1.0.0"', '"1.0.1"');

// wait for 5 seconds and fail if there is Debug Failure. in the console output
await expect(() =>
baseDriver.waitForStderrIncludes('Error: Debug Failure.', 5000)
).rejects.toEqual(
new Error('Exceeded time on waiting for "Error: Debug Failure." to appear in the stderr.')
);

await webpackDriver.waitForNoErrors();
}
);
});
23 changes: 23 additions & 0 deletions test/e2e/fixtures/implementation/typescript-package.fixture
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/// package/package.json
{
"name": "typescript-nested-project",
"version": "1.0.0",
"license": "MIT",
"main": "./index.js",
"types": "./index.d.ts",
"files": [
"./index.js"
]
}

/// package/index.d.ts
export declare function sayHello(who: string): string;

/// package/index.js
"use strict";
exports.__esModule = true;
exports.sayHello = void 0;
function sayHello(who) {
return 'Hello ' + who + '!';
}
exports.sayHello = sayHello;

0 comments on commit b4f7201

Please sign in to comment.