Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: backport package.json ignore on windows #737

Merged
merged 2 commits into from
Apr 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Loading