Skip to content

Commit

Permalink
refactor: test and code
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed May 17, 2023
1 parent 615674e commit d3a753d
Show file tree
Hide file tree
Showing 27 changed files with 210 additions and 179 deletions.
1 change: 0 additions & 1 deletion declarations.d.ts

This file was deleted.

16 changes: 12 additions & 4 deletions lib/CachedInputFileSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,9 @@ module.exports = class CachedInputFileSystem {
const readdir = this._readdirBackend.provide;
this.readdir = /** @type {FileSystem["readdir"]} */ (readdir);
const readdirSync = this._readdirBackend.provideSync;
this.readdirSync = /** @type {SyncFileSystem["readdirSync"]} */ (readdirSync);
this.readdirSync = /** @type {SyncFileSystem["readdirSync"]} */ (
readdirSync
);

this._readFileBackend = createBackend(
duration,
Expand All @@ -510,7 +512,9 @@ module.exports = class CachedInputFileSystem {
const readFile = this._readFileBackend.provide;
this.readFile = /** @type {FileSystem["readFile"]} */ (readFile);
const readFileSync = this._readFileBackend.provideSync;
this.readFileSync = /** @type {SyncFileSystem["readFileSync"]} */ (readFileSync);
this.readFileSync = /** @type {SyncFileSystem["readFileSync"]} */ (
readFileSync
);

this._readJsonBackend = createBackend(
duration,
Expand Down Expand Up @@ -556,7 +560,9 @@ module.exports = class CachedInputFileSystem {
const readJson = this._readJsonBackend.provide;
this.readJson = /** @type {FileSystem["readJson"]} */ (readJson);
const readJsonSync = this._readJsonBackend.provideSync;
this.readJsonSync = /** @type {SyncFileSystem["readJsonSync"]} */ (readJsonSync);
this.readJsonSync = /** @type {SyncFileSystem["readJsonSync"]} */ (
readJsonSync
);

this._readlinkBackend = createBackend(
duration,
Expand All @@ -567,7 +573,9 @@ module.exports = class CachedInputFileSystem {
const readlink = this._readlinkBackend.provide;
this.readlink = /** @type {FileSystem["readlink"]} */ (readlink);
const readlinkSync = this._readlinkBackend.provideSync;
this.readlinkSync = /** @type {SyncFileSystem["readlinkSync"]} */ (readlinkSync);
this.readlinkSync = /** @type {SyncFileSystem["readlinkSync"]} */ (
readlinkSync
);
}

/**
Expand Down
10 changes: 6 additions & 4 deletions lib/ExportsFieldPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ module.exports = class ExportsFieldPlugin {
: request.request;
const exportsField =
/** @type {ExportsField|null|undefined} */
(DescriptionFileUtils.getField(
/** @type {JsonObject} */ (request.descriptionFileData),
this.fieldName
));
(
DescriptionFileUtils.getField(
/** @type {JsonObject} */ (request.descriptionFileData),
this.fieldName
)
);
if (!exportsField) return callback();

if (request.directory) {
Expand Down
10 changes: 6 additions & 4 deletions lib/ImportsFieldPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@ module.exports = class ImportsFieldPlugin {
request.request + request.query + request.fragment;
const importsField =
/** @type {ImportsField|null|undefined} */
(DescriptionFileUtils.getField(
/** @type {JsonObject} */ (request.descriptionFileData),
this.fieldName
));
(
DescriptionFileUtils.getField(
/** @type {JsonObject} */ (request.descriptionFileData),
this.fieldName
)
);
if (!importsField) return callback();

if (request.directory) {
Expand Down
10 changes: 6 additions & 4 deletions lib/MainFieldPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ module.exports = class MainFieldPlugin {
const filename = path.basename(request.descriptionFilePath);
let mainModule =
/** @type {string|null|undefined} */
(DescriptionFileUtils.getField(
/** @type {JsonObject} */ (request.descriptionFileData),
this.options.name
));
(
DescriptionFileUtils.getField(
/** @type {JsonObject} */ (request.descriptionFileData),
this.options.name
)
);

if (
!mainModule ||
Expand Down
40 changes: 20 additions & 20 deletions lib/Resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,18 +204,18 @@ class Resolver {
}
name = toCamelCase(name);
if (/^before/.test(name)) {
return /** @type {ResolveStepHook} */ (this.ensureHook(
name[6].toLowerCase() + name.slice(7)
).withOptions({
stage: -10
}));
return /** @type {ResolveStepHook} */ (
this.ensureHook(name[6].toLowerCase() + name.slice(7)).withOptions({
stage: -10
})
);
}
if (/^after/.test(name)) {
return /** @type {ResolveStepHook} */ (this.ensureHook(
name[5].toLowerCase() + name.slice(6)
).withOptions({
stage: 10
}));
return /** @type {ResolveStepHook} */ (
this.ensureHook(name[5].toLowerCase() + name.slice(6)).withOptions({
stage: 10
})
);
}
/** @type {ResolveStepHook} */
const hook = /** @type {KnownHooks & EnsuredHooks} */ (this.hooks)[name];
Expand All @@ -241,18 +241,18 @@ class Resolver {
}
name = toCamelCase(name);
if (/^before/.test(name)) {
return /** @type {ResolveStepHook} */ (this.getHook(
name[6].toLowerCase() + name.slice(7)
).withOptions({
stage: -10
}));
return /** @type {ResolveStepHook} */ (
this.getHook(name[6].toLowerCase() + name.slice(7)).withOptions({
stage: -10
})
);
}
if (/^after/.test(name)) {
return /** @type {ResolveStepHook} */ (this.getHook(
name[5].toLowerCase() + name.slice(6)
).withOptions({
stage: 10
}));
return /** @type {ResolveStepHook} */ (
this.getHook(name[5].toLowerCase() + name.slice(6)).withOptions({
stage: 10
})
);
}
/** @type {ResolveStepHook} */
const hook = /** @type {KnownHooks & EnsuredHooks} */ (this.hooks)[name];
Expand Down
8 changes: 6 additions & 2 deletions lib/util/entrypoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,9 @@ function conditionalMapping(conditionalMapping_, conditionNames) {
const innerMapping = mapping[condition];
// is nested
if (isConditionalMapping(innerMapping)) {
const conditionalMapping = /** @type {ConditionalMapping} */ (innerMapping);
const conditionalMapping = /** @type {ConditionalMapping} */ (
innerMapping
);
lookup[lookup.length - 1][2] = i + 1;
lookup.push([conditionalMapping, Object.keys(conditionalMapping), 0]);
continue loop;
Expand All @@ -491,7 +493,9 @@ function conditionalMapping(conditionalMapping_, conditionNames) {
const innerMapping = mapping[condition];
// is nested
if (isConditionalMapping(innerMapping)) {
const conditionalMapping = /** @type {ConditionalMapping} */ (innerMapping);
const conditionalMapping = /** @type {ConditionalMapping} */ (
innerMapping
);
lookup[lookup.length - 1][2] = i + 1;
lookup.push([conditionalMapping, Object.keys(conditionalMapping), 0]);
continue loop;
Expand Down
3 changes: 2 additions & 1 deletion lib/util/identifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

"use strict";

const PATH_QUERY_FRAGMENT_REGEXP = /^(#?(?:\0.|[^?#\0])*)(\?(?:\0.|[^#\0])*)?(#.*)?$/;
const PATH_QUERY_FRAGMENT_REGEXP =
/^(#?(?:\0.|[^?#\0])*)(\?(?:\0.|[^#\0])*)?(#.*)?$/;

/**
* @param {string} identifier identifier
Expand Down
1 change: 1 addition & 0 deletions test/alias.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ describe("alias", () => {
},
modules: "/",
useSyncFileSystemCalls: true,
//@ts-ignore
fileSystem: fileSystem
});
});
Expand Down
Loading

0 comments on commit d3a753d

Please sign in to comment.