Skip to content

Commit 29dda1e

Browse files
authored
Merge pull request #320 from nschonni/cspell-setup
chore: add cSpell for spell checking
2 parents b528514 + 0c18298 commit 29dda1e

12 files changed

+579
-102
lines changed

.cspell.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"version": "0.2",
3+
"words": [
4+
"abcxyz",
5+
"addrs",
6+
"anotherhashishere",
7+
"arcanis",
8+
"Builtins",
9+
"complexm",
10+
"endregion",
11+
"entrypoints",
12+
"filesystems",
13+
"hashishere",
14+
"jsons",
15+
"Kopeykin",
16+
"Koppers",
17+
"Maël",
18+
"memfs",
19+
"mergeable",
20+
"Nison",
21+
"opensource",
22+
"pjson",
23+
"pnpapi",
24+
"sokra",
25+
"subpaths",
26+
"tapable",
27+
"undescribed",
28+
"unreviewed",
29+
"vankop",
30+
"wpck",
31+
"zapp",
32+
"zipp",
33+
"zippi",
34+
"zizizi"
35+
],
36+
"ignorePaths": ["package.json", "yarn.lock", "coverage", "*.log"]
37+
}

lib/ModulesInHierachicDirectoriesPlugin.js

Lines changed: 2 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -5,76 +5,5 @@
55

66
"use strict";
77

8-
const forEachBail = require("./forEachBail");
9-
const getPaths = require("./getPaths");
10-
11-
/** @typedef {import("./Resolver")} Resolver */
12-
/** @typedef {import("./Resolver").ResolveStepHook} ResolveStepHook */
13-
14-
module.exports = class ModulesInHierachicDirectoriesPlugin {
15-
/**
16-
* @param {string | ResolveStepHook} source source
17-
* @param {string | Array<string>} directories directories
18-
* @param {string | ResolveStepHook} target target
19-
*/
20-
constructor(source, directories, target) {
21-
this.source = source;
22-
this.directories = /** @type {Array<string>} */ ([]).concat(directories);
23-
this.target = target;
24-
}
25-
26-
/**
27-
* @param {Resolver} resolver the resolver
28-
* @returns {void}
29-
*/
30-
apply(resolver) {
31-
const target = resolver.ensureHook(this.target);
32-
resolver
33-
.getHook(this.source)
34-
.tapAsync(
35-
"ModulesInHierachicDirectoriesPlugin",
36-
(request, resolveContext, callback) => {
37-
const fs = resolver.fileSystem;
38-
const addrs = getPaths(request.path)
39-
.paths.map(p => {
40-
return this.directories.map(d => resolver.join(p, d));
41-
})
42-
.reduce((array, p) => {
43-
array.push.apply(array, p);
44-
return array;
45-
}, []);
46-
forEachBail(
47-
addrs,
48-
(addr, callback) => {
49-
fs.stat(addr, (err, stat) => {
50-
if (!err && stat && stat.isDirectory()) {
51-
const obj = {
52-
...request,
53-
path: addr,
54-
request: "./" + request.request,
55-
module: false
56-
};
57-
const message = "looking for modules in " + addr;
58-
return resolver.doResolve(
59-
target,
60-
obj,
61-
message,
62-
resolveContext,
63-
callback
64-
);
65-
}
66-
if (resolveContext.log)
67-
resolveContext.log(
68-
addr + " doesn't exist or is not a directory"
69-
);
70-
if (resolveContext.missingDependencies)
71-
resolveContext.missingDependencies.add(addr);
72-
return callback();
73-
});
74-
},
75-
callback
76-
);
77-
}
78-
);
79-
}
80-
};
8+
// TODO remove in next major
9+
module.exports = require("./ModulesInHierarchicalDirectoriesPlugin");
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
MIT License http://www.opensource.org/licenses/mit-license.php
3+
Author Tobias Koppers @sokra
4+
*/
5+
6+
"use strict";
7+
8+
const forEachBail = require("./forEachBail");
9+
const getPaths = require("./getPaths");
10+
11+
/** @typedef {import("./Resolver")} Resolver */
12+
/** @typedef {import("./Resolver").ResolveStepHook} ResolveStepHook */
13+
14+
module.exports = class ModulesInHierarchicalDirectoriesPlugin {
15+
/**
16+
* @param {string | ResolveStepHook} source source
17+
* @param {string | Array<string>} directories directories
18+
* @param {string | ResolveStepHook} target target
19+
*/
20+
constructor(source, directories, target) {
21+
this.source = source;
22+
this.directories = /** @type {Array<string>} */ ([]).concat(directories);
23+
this.target = target;
24+
}
25+
26+
/**
27+
* @param {Resolver} resolver the resolver
28+
* @returns {void}
29+
*/
30+
apply(resolver) {
31+
const target = resolver.ensureHook(this.target);
32+
resolver
33+
.getHook(this.source)
34+
.tapAsync(
35+
"ModulesInHierarchicalDirectoriesPlugin",
36+
(request, resolveContext, callback) => {
37+
const fs = resolver.fileSystem;
38+
const addrs = getPaths(request.path)
39+
.paths.map(p => {
40+
return this.directories.map(d => resolver.join(p, d));
41+
})
42+
.reduce((array, p) => {
43+
array.push.apply(array, p);
44+
return array;
45+
}, []);
46+
forEachBail(
47+
addrs,
48+
(addr, callback) => {
49+
fs.stat(addr, (err, stat) => {
50+
if (!err && stat && stat.isDirectory()) {
51+
const obj = {
52+
...request,
53+
path: addr,
54+
request: "./" + request.request,
55+
module: false
56+
};
57+
const message = "looking for modules in " + addr;
58+
return resolver.doResolve(
59+
target,
60+
obj,
61+
message,
62+
resolveContext,
63+
callback
64+
);
65+
}
66+
if (resolveContext.log)
67+
resolveContext.log(
68+
addr + " doesn't exist or is not a directory"
69+
);
70+
if (resolveContext.missingDependencies)
71+
resolveContext.missingDependencies.add(addr);
72+
return callback();
73+
});
74+
},
75+
callback
76+
);
77+
}
78+
);
79+
}
80+
};

lib/ResolverFactory.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const ImportsFieldPlugin = require("./ImportsFieldPlugin");
2323
const JoinRequestPartPlugin = require("./JoinRequestPartPlugin");
2424
const JoinRequestPlugin = require("./JoinRequestPlugin");
2525
const MainFieldPlugin = require("./MainFieldPlugin");
26-
const ModulesInHierachicDirectoriesPlugin = require("./ModulesInHierachicDirectoriesPlugin");
26+
const ModulesInHierarchicalDirectoriesPlugin = require("./ModulesInHierarchicalDirectoriesPlugin");
2727
const ModulesInRootPlugin = require("./ModulesInRootPlugin");
2828
const NextPlugin = require("./NextPlugin");
2929
const ParsePlugin = require("./ParsePlugin");
@@ -73,7 +73,7 @@ const UseFilePlugin = require("./UseFilePlugin");
7373
* @property {boolean=} fullySpecified The request is already fully specified and no extensions or directories are resolved for it
7474
* @property {boolean=} resolveToContext Resolve to a context instead of a file
7575
* @property {(string|RegExp)[]=} restrictions A list of resolve restrictions
76-
* @property {boolean=} useSyncFileSystemCalls Use only the sync constiants of the file system calls
76+
* @property {boolean=} useSyncFileSystemCalls Use only the sync constraints of the file system calls
7777
* @property {boolean=} preferRelative Prefer to resolve module requests as relative requests before falling back to modules
7878
* @property {boolean=} preferAbsolute Prefer to resolve server-relative urls as absolute paths before falling back to resolve in roots
7979
*/
@@ -280,7 +280,7 @@ exports.createResolver = function (options) {
280280

281281
resolver.ensureHook("resolve");
282282
resolver.ensureHook("internalResolve");
283-
resolver.ensureHook("newInteralResolve");
283+
resolver.ensureHook("newInternalResolve");
284284
resolver.ensureHook("parsedResolve");
285285
resolver.ensureHook("describedResolve");
286286
resolver.ensureHook("internal");
@@ -302,6 +302,11 @@ exports.createResolver = function (options) {
302302
resolver.ensureHook("existingFile");
303303
resolver.ensureHook("resolved");
304304

305+
// TODO remove in next major
306+
// cspell:word Interal
307+
// Backward-compat
308+
resolver.hooks.newInteralResolve = resolver.hooks.newInternalResolve;
309+
305310
// resolve
306311
for (const { source, resolveOptions } of [
307312
{ source: "resolve", resolveOptions: { fullySpecified } },
@@ -406,7 +411,7 @@ exports.createResolver = function (options) {
406411
if (Array.isArray(item)) {
407412
if (item.includes("node_modules") && pnpApi) {
408413
plugins.push(
409-
new ModulesInHierachicDirectoriesPlugin(
414+
new ModulesInHierarchicalDirectoriesPlugin(
410415
"raw-module",
411416
item.filter(i => i !== "node_modules"),
412417
"module"
@@ -417,7 +422,11 @@ exports.createResolver = function (options) {
417422
);
418423
} else {
419424
plugins.push(
420-
new ModulesInHierachicDirectoriesPlugin("raw-module", item, "module")
425+
new ModulesInHierarchicalDirectoriesPlugin(
426+
"raw-module",
427+
item,
428+
"module"
429+
)
421430
);
422431
}
423432
} else {

lib/SymlinkPlugin.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module.exports = class SymlinkPlugin {
3434
.tapAsync("SymlinkPlugin", (request, resolveContext, callback) => {
3535
if (request.ignoreSymlinks) return callback();
3636
const pathsResult = getPaths(request.path);
37-
const pathSeqments = pathsResult.seqments;
37+
const pathSegments = pathsResult.segments;
3838
const paths = pathsResult.paths;
3939

4040
let containsSymlink = false;
@@ -47,7 +47,7 @@ module.exports = class SymlinkPlugin {
4747
resolveContext.fileDependencies.add(path);
4848
fs.readlink(path, (err, result) => {
4949
if (!err && result) {
50-
pathSeqments[idx] = result;
50+
pathSegments[idx] = result;
5151
containsSymlink = true;
5252
// Shortcut when absolute symlink found
5353
const resultType = getType(result.toString());
@@ -63,11 +63,11 @@ module.exports = class SymlinkPlugin {
6363
},
6464
(err, idx) => {
6565
if (!containsSymlink) return callback();
66-
const resultSeqments =
66+
const resultSegments =
6767
typeof idx === "number"
68-
? pathSeqments.slice(0, idx + 1)
69-
: pathSeqments.slice();
70-
const result = resultSeqments.reduceRight((a, b) => {
68+
? pathSegments.slice(0, idx + 1)
69+
: pathSegments.slice();
70+
const result = resultSegments.reduceRight((a, b) => {
7171
return resolver.join(a, b);
7272
});
7373
const obj = {

lib/getPaths.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,24 @@
66
"use strict";
77

88
module.exports = function getPaths(path) {
9-
if (path === "/") return { paths: ["/"], seqments: [""] };
9+
if (path === "/") return { paths: ["/"], segments: [""] };
1010
const parts = path.split(/(.*?[\\/]+)/);
1111
const paths = [path];
12-
const seqments = [parts[parts.length - 1]];
12+
const segments = [parts[parts.length - 1]];
1313
let part = parts[parts.length - 1];
1414
path = path.substr(0, path.length - part.length - 1);
1515
for (let i = parts.length - 2; i > 2; i -= 2) {
1616
paths.push(path);
1717
part = parts[i];
1818
path = path.substr(0, path.length - part.length) || "/";
19-
seqments.push(part.substr(0, part.length - 1));
19+
segments.push(part.substr(0, part.length - 1));
2020
}
2121
part = parts[1];
22-
seqments.push(part);
22+
segments.push(part);
2323
paths.push(part);
2424
return {
2525
paths: paths,
26-
seqments: seqments
26+
segments: segments
2727
};
2828
};
2929

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"devDependencies": {
2121
"@types/mocha": "^8.0.3",
2222
"@types/node": "^14.11.1",
23+
"cspell": "4.2.8",
2324
"eslint": "^7.9.0",
2425
"eslint-config-prettier": "^6.11.0",
2526
"eslint-plugin-jsdoc": "^30.5.1",
@@ -42,7 +43,7 @@
4243
"types": "types.d.ts",
4344
"homepage": "http://github.com/webpack/enhanced-resolve",
4445
"scripts": {
45-
"lint": "yarn run code-lint && yarn run type-lint && yarn run special-lint",
46+
"lint": "yarn run code-lint && yarn run type-lint && yarn run special-lint && yarn run spelling",
4647
"fix": "yarn run code-lint-fix && yarn run special-lint-fix",
4748
"code-lint": "eslint --cache lib test",
4849
"code-lint-fix": "eslint --cache lib test --fix",
@@ -51,6 +52,7 @@
5152
"special-lint-fix": "node node_modules/tooling/inherit-types --write && node node_modules/tooling/format-file-header --write && node node_modules/tooling/generate-types --write",
5253
"pretty": "prettier --loglevel warn --write \"lib/**/*.{js,json}\" \"test/*.js\"",
5354
"pretest": "yarn lint",
55+
"spelling": "cspell \"**/*.*\"",
5456
"test": "mocha --full-trace --check-leaks",
5557
"test:only": "mocha --full-trace --check-leaks",
5658
"precover": "yarn lint",

test/getPaths.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@ require("should");
33
const getPaths = require("../lib/getPaths");
44

55
/**
6-
* @type {[string,{paths: string[], seqments: string[]}][]}
6+
* @type {[string,{paths: string[], segments: string[]}][]}
77
*/
88
const cases = [
9-
["/a", { paths: ["/a", "/"], seqments: ["a", "/"] }],
10-
["/a/", { paths: ["/a/", "/a", "/"], seqments: ["", "a", "/"] }],
11-
["/a/b", { paths: ["/a/b", "/a", "/"], seqments: ["b", "a", "/"] }],
9+
["/a", { paths: ["/a", "/"], segments: ["a", "/"] }],
10+
["/a/", { paths: ["/a/", "/a", "/"], segments: ["", "a", "/"] }],
11+
["/a/b", { paths: ["/a/b", "/a", "/"], segments: ["b", "a", "/"] }],
1212
[
1313
"/a/b/",
14-
{ paths: ["/a/b/", "/a/b", "/a", "/"], seqments: ["", "b", "a", "/"] }
14+
{ paths: ["/a/b/", "/a/b", "/a", "/"], segments: ["", "b", "a", "/"] }
1515
],
16-
["/", { paths: ["/"], seqments: [""] }]
16+
["/", { paths: ["/"], segments: [""] }]
1717
];
1818

1919
cases.forEach(case_ => {
2020
it(case_[0], () => {
21-
const { paths, seqments } = getPaths(case_[0]);
21+
const { paths, segments } = getPaths(case_[0]);
2222
paths.should.be.eql(case_[1].paths);
23-
seqments.should.be.eql(case_[1].seqments);
23+
segments.should.be.eql(case_[1].segments);
2424
});
2525
});

test/resolve.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ describe("resolve", function () {
309309
});
310310
});
311311

312-
it("should not crash when passing undefined everywere", done => {
312+
it("should not crash when passing undefined everywhere", done => {
313313
resolve(undefined, undefined, undefined, undefined, err => {
314314
err.should.be.instanceof(Error);
315315
done();

tooling/format-file-header.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const path = require("path");
22
const fs = require("fs");
33

44
// When --write is set, files will be written in place
5-
// Elsewise it only prints outdated files
5+
// Otherwise it only prints outdated files
66
const doWrite = process.argv.includes("--write");
77

88
const allFiles = new Set();

0 commit comments

Comments
 (0)