Bump eslint-plugin-import to avoid vulnerability in dependency

This commit is contained in:
Henry Mercer 2023-01-18 20:26:59 +00:00
parent 10695e6a20
commit ed9506bbaf
1660 changed files with 67726 additions and 27926 deletions

View file

@ -1,8 +0,0 @@
{
"include": ["src/**/*.{ts,tsx}"],
"exclude": ["src/register.ts"],
"extension": [".ts", ".tsx"],
"reporter": ["json"],
"sourceMap": true,
"all": true
}

View file

@ -7,6 +7,63 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
## [3.14.1] - 2022-03-22
### Fixed
- Use minimist 1.2.6 for all depencencies becuase of pollution vulnerability. See PR [#197](https://github.com/dividab/tsconfig-paths/pull/197). Thanks to [@gopijaganthan](https://github.com/gopijaganthan) for this fix!
## [3.14.0] - 2022-03-13
### Added
- Support for path mapping starting with `/`. See PR [#180](https://github.com/dividab/tsconfig-paths/pull/180), issue [#113](https://github.com/dividab/tsconfig-paths/issues/113), and issue [#128](https://github.com/dividab/tsconfig-paths/issues/128). Thanks to [@benevbright](https://github.com/benevbright) for this fix!
## [3.13.0] - 2022-03-03
### Added
- Include file extension in paths resolved from package.json "main" field. See PR [#135](https://github.com/dividab/tsconfig-paths/pull/135) and issue [#133](https://github.com/dividab/tsconfig-paths/issues/133). Thanks to [@katywings](https://github.com/katywings) for this fix!
## [3.12.0] - 2021-08-24
- Add support for baseUrl override using TS_NODE_BASEURL env var #185 and #114. Thanks to @ejhayes and @information-security for these PRs!
## [3.11.0] - 2021-08-24
- Reverted upgrade of json5 due to being a breaking change. See PR #173.
## [3.10.1] - 2021-07-06
### Fixed
- Add register.js to published files
## [3.10.0] - 2021-07-06
### Added
- feat(tsconfig-loader): extends config from node_modules (#106). Thanks to @zorji for this PR!
### Fixed
- Update CHANGELOG.md (#96). Thanks to @OliverJAsh for this PR!
- Fix "bootstraping" typo (#111). Thanks to @KRMisha for this PR!
- Update Readme fixes #116 (#123). Thanks to @benwinding for this PR!
- Fixed typo (#144). Thanks to @mprinc for this PR!
- [TYPO] src/mapping-entry.ts (#145). Thanks to @mprinc for this PR!
- docs(README): fix typos (#156). Thanks to @PiDelport for this PR!
- deps: bump json5 to use type definition provided officially (#158). Thanks to @koba04 for this PR!
- Update tsconfig-loader.ts (#161). Thanks to @fecqs for this PR!
- fix typo (#165). Thanks to @wonda-tea-coffee for this PR!
- Add file extenstion to typings property value (#151). Thanks to @dangrussell for this PR!
## [3.9.0] - 2019-09-12
### Added
- Make extension config override instead of deep merge. See PR [#95](https://github.com/dividab/tsconfig-paths/pull/95) and issue [#94](https://github.com/dividab/tsconfig-paths/issues/94). Thanks to [@OliverJAsh](https://github.com/OliverJAsh) for this addition!
## [3.8.0] - 2019-02-05
### Added
@ -53,7 +110,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Fixed
- Adding json file extention to extends property, [#40](https://github.com/dividab/tsconfig-paths/pull/40). Thanks to [@cwhite-connectfirst](https://github.com/cwhite-connectfirst) for this fixing this!
- Adding json file extension to extends property, [#40](https://github.com/dividab/tsconfig-paths/pull/40). Thanks to [@cwhite-connectfirst](https://github.com/cwhite-connectfirst) for this fixing this!
## [3.3.1] - 2018-04-17
@ -275,7 +332,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Initial version.
[unreleased]: https://github.com/dividab/tsconfig-paths/compare/3.8.0...master
[unreleased]: https://github.com/dividab/tsconfig-paths/compare/v3.9.0...master
[3.9.0]: https://github.com/dividab/tsconfig-paths/compare/v3.8.0...v3.9.0
[3.8.0]: https://github.com/dividab/tsconfig-paths/compare/3.7.0...3.8.0
[3.7.0]: https://github.com/dividab/tsconfig-paths/compare/3.6.0...3.7.0
[3.6.0]: https://github.com/dividab/tsconfig-paths/compare/3.5.0...3.6.0

View file

@ -1,7 +1,7 @@
# tsconfig-paths
[![npm version][version-image]][version-url]
[![travis build][travis-image]][travis-url]
[![build][build-image]][build-url]
[![Coverage Status][codecov-image]][codecov-url]
[![MIT license][license-image]][license-url]
[![code style: prettier][prettier-image]][prettier-url]
@ -10,7 +10,7 @@ Use this to load modules whose location is specified in the `paths` section of `
Typescript by default mimics the Node.js runtime resolution strategy of modules. But it also allows the use of [path mapping](https://www.typescriptlang.org/docs/handbook/module-resolution.html) which allows arbitrary module paths (that doesn't start with "/" or ".") to be specified and mapped to physical paths in the filesystem. The typescript compiler can resolve these paths from `tsconfig` so it will compile OK. But if you then try to execute the compiled files with node (or ts-node), it will only look in the `node_modules` folders all the way up to the root of the filesystem and thus will not find the modules specified by `paths` in `tsconfig`.
If you require this package's `tsconfig-paths/register` module it will read the `paths` from `tsconfig.json` and convert node's module loading calls into to physcial file paths that node can load.
If you require this package's `tsconfig-paths/register` module it will read the `paths` from `tsconfig.json` and convert node's module loading calls into to physical file paths that node can load.
## How to install
@ -30,6 +30,10 @@ npm install --save-dev tsconfig-paths
`node -r tsconfig-paths/register main.js`
If `process.env.TS_NODE_BASEURL` is set it will override the value of `baseUrl` in tsconfig.json:
`TS_NODE_BASEURL=./dist node -r tsconfig-paths/register main.js`
### With ts-node
`ts-node -r tsconfig-paths/register main.ts`
@ -52,10 +56,43 @@ mocha -r ts-node/register -r tsconfig-paths/register "test/**/*.ts"
As long as the command has something similar to a `--require` option that can load a module before it starts, tsconfig-paths should be able to work with it.
## Bootstraping with explicit params
### With `ts-node` and VSCode
The following is an example configuration for the `.vscode/launch.json`.
```js
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Functions",
"request": "launch",
"type": "node",
"runtimeArgs": [
"-r",
"${workspaceFolder}/functions/node_modules/ts-node/register",
"-r",
"${workspaceFolder}/functions/node_modules/tsconfig-paths/register"
],
"args": ["${workspaceFolder}/functions/src/index.ts"],
"cwd": "${workspaceFolder}",
"protocol": "inspector",
"env": {
"NODE_ENV": "development",
"TS_NODE_PROJECT": "${workspaceFolder}/functions/tsconfig.json"
},
"outFiles": ["${workspaceFolder}/functions/lib/**/*.js"]
}
]
}
```
## Bootstrapping with explicit params
If you want more granular control over tsconfig-paths you can bootstrap it. This can be useful if you for instance have compiled with `tsc` to another directory where `tsconfig.json` doesn't exists.
For example, create a wrapper script called `tsconfig-paths-bootstrap.js` with the contents below:
```javascript
const tsConfig = require("./tsconfig.json");
const tsConfigPaths = require("tsconfig-paths");
@ -63,7 +100,7 @@ const tsConfigPaths = require("tsconfig-paths");
const baseUrl = "./"; // Either absolute or relative path. If relative it's resolved to current working directory.
const cleanup = tsConfigPaths.register({
baseUrl,
paths: tsConfig.compilerOptions.paths
paths: tsConfig.compilerOptions.paths,
});
// When path registration is no longer needed
@ -176,7 +213,7 @@ export function createMatchPath(
): MatchPath {
```
The `createMatchPath` function will create a function that can match paths. It accepts `baseUrl` and `paths` directly as they are specified in tsconfig and will handle resolving paths to absolute form. The created function has the signare specified by the type `MatchPath` above.
The `createMatchPath` function will create a function that can match paths. It accepts `baseUrl` and `paths` directly as they are specified in tsconfig and will handle resolving paths to absolute form. The created function has the signature specified by the type `MatchPath` above.
### matchFromAbsolutePaths
@ -186,7 +223,7 @@ The `createMatchPath` function will create a function that can match paths. It a
* @param absolutePathMappings The paths to try as specified in tsconfig but resolved to absolute form.
* @param requestedModule The required module name.
* @param readJson Function that can read json from a path (useful for testing).
* @param fileExists Function that checks for existance of a file at a path (useful for testing).
* @param fileExists Function that checks for existence of a file at a path (useful for testing).
* @param extensions File extensions to probe for (useful for testing).
* @param mainFields A list of package.json field names to try when resolving module files.
* @returns the found path, or undefined if no path was found.
@ -201,7 +238,7 @@ export function matchFromAbsolutePaths(
): string | undefined {
```
This function is lower level and requries that the paths as already been resolved to absolute form and sorted in correct order into an array.
This function is lower level and requires that the paths as already been resolved to absolute form and sorted in correct order into an array.
### createMatchPathAsync
@ -221,8 +258,8 @@ yarn version --major
[version-image]: https://img.shields.io/npm/v/tsconfig-paths.svg?style=flat
[version-url]: https://www.npmjs.com/package/tsconfig-paths
[travis-image]: https://travis-ci.com/dividab/tsconfig-paths.svg?branch=master&style=flat
[travis-url]: https://travis-ci.com/dividab/tsconfig-paths
[build-image]: https://github.com/dividab/tsconfig-paths/workflows/CI/badge.svg
[build-url]: https://github.com/dividab/tsconfig-paths/actions/workflows/ci.yml?query=branch%3Amaster
[codecov-image]: https://codecov.io/gh/dividab/tsconfig-paths/branch/master/graph/badge.svg
[codecov-url]: https://codecov.io/gh/dividab/tsconfig-paths
[license-image]: https://img.shields.io/github/license/dividab/tsconfig-paths.svg?style=flat

View file

@ -0,0 +1 @@
export {};

View file

@ -0,0 +1,88 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var config_loader_1 = require("../config-loader");
var path_1 = require("path");
describe("config-loader", function () {
it("should use explicitParams when set", function () {
var result = (0, config_loader_1.configLoader)({
explicitParams: {
baseUrl: "/foo/bar",
paths: {
asd: ["asd"],
},
},
cwd: "/baz",
});
var successResult = result;
// assert.equal(successResult.resultType, "success");
// assert.equal(successResult.absoluteBaseUrl, "/foo/bar");
// assert.equal(successResult.paths["asd"][0], "asd");
expect(successResult.resultType).toBe("success");
expect(successResult.absoluteBaseUrl).toBe("/foo/bar");
expect(successResult.paths["asd"][0]).toBe("asd");
});
it("should use explicitParams when set and add cwd when path is relative", function () {
var result = (0, config_loader_1.configLoader)({
explicitParams: {
baseUrl: "bar/",
paths: {
asd: ["asd"],
},
},
cwd: "/baz",
});
var successResult = result;
// assert.equal(successResult.resultType, "success");
// assert.equal(successResult.absoluteBaseUrl, join("/baz", "bar/"));
expect(successResult.resultType).toBe("success");
expect(successResult.absoluteBaseUrl).toBe((0, path_1.join)("/baz", "bar/"));
});
it("should fallback to tsConfigLoader when explicitParams is not set", function () {
var result = (0, config_loader_1.configLoader)({
explicitParams: undefined,
cwd: "/baz",
// tslint:disable-next-line:no-any
tsConfigLoader: function (_) { return ({
tsConfigPath: "/baz/tsconfig.json",
baseUrl: "./src",
paths: {},
}); },
});
var successResult = result;
// assert.equal(successResult.resultType, "success");
// assert.equal(successResult.absoluteBaseUrl, join("/baz", "src"));
expect(successResult.resultType).toBe("success");
expect(successResult.absoluteBaseUrl).toBe((0, path_1.join)("/baz", "src"));
});
it("should show an error message when baseUrl is missing", function () {
var result = (0, config_loader_1.configLoader)({
explicitParams: undefined,
cwd: "/baz",
// tslint:disable-next-line:no-any
tsConfigLoader: function (_) { return ({
tsConfigPath: "/baz/tsconfig.json",
baseUrl: undefined,
paths: {},
}); },
});
var failResult = result;
// assert.equal(failResult.resultType, "failed");
// assert.isTrue(failResult.message.indexOf("baseUrl") > -1);
expect(failResult.resultType).toBe("failed");
expect(failResult.message.indexOf("baseUrl") > -1).toBeTruthy();
});
it("should presume cwd to be a tsconfig file when loadConfig is called with absolute path to tsconfig.json", function () {
// using tsconfig-named.json to ensure that future changes to fix
// https://github.com/dividab/tsconfig-paths/issues/31
// do not pass this test case just because of a directory walk looking
// for tsconfig.json
var configFile = (0, path_1.join)(__dirname, "tsconfig-named.json");
var result = (0, config_loader_1.loadConfig)(configFile);
var successResult = result;
// assert.equal(successResult.resultType, "success");
// assert.equal(successResult.configFileAbsolutePath, configFile);
expect(successResult.resultType).toBe("success");
expect(successResult.configFileAbsolutePath).toBe(configFile);
});
});
//# sourceMappingURL=config-loader.test.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"config-loader.test.js","sourceRoot":"","sources":["../../src/__tests__/config-loader.test.ts"],"names":[],"mappings":";;AAAA,kDAK0B;AAC1B,6BAA4B;AAE5B,QAAQ,CAAC,eAAe,EAAE;IACxB,EAAE,CAAC,oCAAoC,EAAE;QACvC,IAAM,MAAM,GAAG,IAAA,4BAAY,EAAC;YAC1B,cAAc,EAAE;gBACd,OAAO,EAAE,UAAU;gBACnB,KAAK,EAAE;oBACL,GAAG,EAAE,CAAC,KAAK,CAAC;iBACb;aACF;YACD,GAAG,EAAE,MAAM;SACZ,CAAC,CAAC;QAEH,IAAM,aAAa,GAAG,MAAmC,CAAC;QAC1D,qDAAqD;QACrD,2DAA2D;QAC3D,sDAAsD;QACtD,MAAM,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACjD,MAAM,CAAC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?: boolean;
readonly absoluteBaseUrl: string;
readonly paths: {
[key: string]: Array<string>;
};
readonly mainFields?: string[];
readonly addMatchAll?: boolean;
readonly existingFiles: ReadonlyArray<string>;
readonly requestedModule: string;
readonly extensions: ReadonlyArray<string>;
readonly packageJson?: {};
readonly expectedPath: string | undefined;
}
export declare const tests: ReadonlyArray<OneTest>;

View file

@ -0,0 +1,205 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.tests = void 0;
var path_1 = require("path");
var filesystem_1 = require("../../filesystem");
var defaultExtensionsWhenRunningInTsNode = [
".js",
".json",
".node",
".ts",
".tsx",
];
exports.tests = [
{
name: "should locate path that matches with star and exists",
absoluteBaseUrl: "/root/",
paths: {
"lib/*": ["location/*"],
},
existingFiles: [(0, path_1.join)("/root", "location", "mylib", "index.ts")],
requestedModule: "lib/mylib",
expectedPath: (0, path_1.dirname)((0, path_1.join)("/root", "location", "mylib", "index.ts")),
extensions: defaultExtensionsWhenRunningInTsNode,
},
{
name: "should resolve to correct path when many are specified",
absoluteBaseUrl: "/root/",
paths: {
"lib/*": ["foo1/*", "foo2/*", "location/*", "foo3/*"],
},
existingFiles: [(0, path_1.join)("/root", "location", "mylib", "index.ts")],
requestedModule: "lib/mylib",
extensions: [".ts"],
expectedPath: (0, path_1.dirname)((0, path_1.join)("/root", "location", "mylib", "index.ts")),
},
{
name: "should locate path that matches with star and prioritize pattern with longest prefix",
absoluteBaseUrl: "/root/",
paths: {
"*": ["location/*"],
"lib/*": ["location/*"],
},
existingFiles: [
(0, path_1.join)("/root", "location", "lib", "mylib", "index.ts"),
(0, path_1.join)("/root", "location", "mylib", "index.ts"),
],
requestedModule: "lib/mylib",
expectedPath: (0, path_1.dirname)((0, path_1.join)("/root", "location", "mylib", "index.ts")),
extensions: defaultExtensionsWhenRunningInTsNode,
},
{
name: "should locate path that matches with star and exists with extension",
absoluteBaseUrl: "/root/",
paths: { "lib/*": ["location/*"] },
existingFiles: [(0, path_1.join)("/root", "location", "mylib.myext")],
requestedModule: "lib/mylib",
extensions: [".js", ".myext"],
expectedPath: (0, filesystem_1.removeExtension)((0, path_1.join)("/root", "location", "mylib.myext")),
},
{
name: "should resolve request with extension specified",
absoluteBaseUrl: "/root/",
paths: { "lib/*": ["location/*"] },
existingFiles: [(0, path_1.join)("/root", "location", "test.jpg")],
requestedModule: "lib/test.jpg",
expectedPath: (0, path_1.join)("/root", "location", "test.jpg"),
extensions: defaultExtensionsWhenRunningInTsNode,
},
{
name: "should locate path that matches without star and exists",
absoluteBaseUrl: "/root/",
paths: {
"lib/foo": ["location/foo"],
},
existingFiles: [(0, path_1.join)("/root", "location", "foo.ts")],
requestedModule: "lib/foo",
expectedPath: (0, filesystem_1.removeExtension)((0, path_1.join)("/root", "location", "foo.ts")),
extensions: defaultExtensionsWhenRunningInTsNode,
},
{
name: "should resolve to parent folder when filename is in subfolder",
absoluteBaseUrl: "/root/",
paths: { "lib/*": ["location/*"] },
existingFiles: [(0, path_1.join)("/root", "location", "mylib", "index.ts")],
requestedModule: "lib/mylib",
expectedPath: (0, path_1.dirname)((0, path_1.join)("/root", "location", "mylib", "index.ts")),
extensions: defaultExtensionsWhenRunningInTsNode,
},
{
name: "should resolve from main field in package.json",
absoluteBaseUrl: "/root/",
paths: { "lib/*": ["location/*"] },
existingFiles: [(0, path_1.join)("/root", "location", "mylib", "kalle.ts")],
packageJson: { main: "./kalle.ts" },
requestedModule: "lib/mylib",
expectedPath: (0, path_1.join)("/root", "location", "mylib", "kalle.ts"),
extensions: defaultExtensionsWhenRunningInTsNode,
},
{
name: "should resolve from main field in package.json (js)",
absoluteBaseUrl: "/root",
paths: { "lib/*": ["location/*"] },
existingFiles: [(0, path_1.join)("/root", "location", "mylib.js", "kalle.js")],
packageJson: { main: "./kalle.js" },
requestedModule: "lib/mylib.js",
extensions: [".ts", ".js"],
expectedPath: (0, path_1.join)("/root", "location", "mylib.js", "kalle.js"),
},
{
name: "should resolve from list of fields by priority in package.json",
absoluteBaseUrl: "/root/",
paths: { "lib/*": ["location/*"] },
mainFields: ["missing", "browser", "main"],
packageJson: { main: "./main.js", browser: "./browser.js" },
existingFiles: [
(0, path_1.join)("/root", "location", "mylibjs", "main.js"),
(0, path_1.join)("/root", "location", "mylibjs", "browser.js"), // browserFilePath
],
extensions: [".ts", ".js"],
requestedModule: "lib/mylibjs",
expectedPath: (0, path_1.join)("/root", "location", "mylibjs", "browser.js"),
},
{
name: "should ignore field mappings to missing files in package.json",
absoluteBaseUrl: "/root/",
paths: { "lib/*": ["location/*"] },
mainFields: ["browser", "main"],
existingFiles: [(0, path_1.join)("/root", "location", "mylibjs", "kalle.js")],
requestedModule: "lib/mylibjs",
packageJson: {
main: "./kalle.js",
browser: "./nope.js",
},
extensions: [".ts", ".js"],
expectedPath: (0, path_1.join)("/root", "location", "mylibjs", "kalle.js"),
},
{
name: "should ignore advanced field mappings in package.json",
absoluteBaseUrl: "/root/",
paths: { "lib/*": ["location/*"] },
existingFiles: [
(0, path_1.join)("/root", "location", "mylibjs", "kalle.js"),
(0, path_1.join)("/root", "location", "mylibjs", "browser.js"),
],
requestedModule: "lib/mylibjs",
packageJson: {
main: "./kalle.js",
browser: { mylibjs: "./browser.js", "./kalle.js": "./browser.js" },
},
extensions: [".ts", ".js"],
expectedPath: (0, path_1.join)("/root", "location", "mylibjs", "kalle.js"),
},
{
name: "should resolve to with the help of baseUrl when not explicitly set",
absoluteBaseUrl: "/root/",
paths: {},
existingFiles: [(0, path_1.join)("/root", "mylib", "index.ts")],
requestedModule: "mylib",
expectedPath: (0, path_1.dirname)((0, path_1.join)("/root", "mylib", "index.ts")),
extensions: defaultExtensionsWhenRunningInTsNode,
},
{
name: "should not resolve with the help of baseUrl when asked not to",
absoluteBaseUrl: "/root/",
paths: {},
addMatchAll: false,
existingFiles: [(0, path_1.join)("/root", "mylib", "index.ts")],
requestedModule: "mylib",
expectedPath: undefined,
extensions: defaultExtensionsWhenRunningInTsNode,
},
{
name: "should not locate path that does not match",
absoluteBaseUrl: "/root/",
paths: { "lib/*": ["location/*"] },
existingFiles: [(0, path_1.join)("root", "location", "mylib")],
requestedModule: "mylib",
expectedPath: undefined,
extensions: defaultExtensionsWhenRunningInTsNode,
},
{
name: "should not resolve typings file (index.d.ts)",
absoluteBaseUrl: "/root/",
paths: {
"lib/*": ["location/*"],
},
existingFiles: [(0, path_1.join)("/root", "location", "mylib", "index.d.ts")],
requestedModule: "lib/mylib",
expectedPath: undefined,
extensions: defaultExtensionsWhenRunningInTsNode,
},
{
name: "should resolve main file with cjs file extension",
absoluteBaseUrl: "/root/",
paths: {},
existingFiles: [(0, path_1.join)("/root", "mylib", "index.cjs")],
packageJson: {
main: "./index.cjs",
},
requestedModule: "mylib",
expectedPath: (0, path_1.join)("/root", "mylib", "index.cjs"),
extensions: defaultExtensionsWhenRunningInTsNode,
},
];
//# sourceMappingURL=match-path-data.js.map

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1 @@
export {};

View file

@ -0,0 +1,64 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Filesystem = require("../filesystem");
var path = require("path");
describe("filesystem", function () {
var fileThatExists = path.join(__dirname, "../../package.json");
var fileThatNotExists = path.join(__dirname, "../../package2.json");
it("should find file that exists, sync", function () {
var result = Filesystem.fileExistsSync(fileThatExists);
// assert.equal(result, true);
expect(result).toBe(true);
});
it("should not find file that not exists, sync", function () {
var result = Filesystem.fileExistsSync(fileThatNotExists);
// assert.equal(result, false);
expect(result).toBe(false);
});
it("should find file that exists, async", function (done) {
Filesystem.fileExistsAsync(fileThatExists, function (_err, result) {
try {
// assert.equal(result, true);
expect(result).toBe(true);
done();
}
catch (error) {
done(error);
}
});
});
it("should not find file that not exists, async", function (done) {
Filesystem.fileExistsAsync(fileThatNotExists, function (_err, result) {
try {
// assert.equal(result, false);
expect(result).toBe(false);
done();
}
catch (error) {
done(error);
}
});
});
it("should load json, sync", function () {
var result = Filesystem.readJsonFromDiskSync(fileThatExists);
// assert.isOk(result);
expect(result);
// assert.equal(result.main, "lib/index.js");
expect(result.main).toBe("lib/index.js");
});
it("should load json, async", function (done) {
Filesystem.readJsonFromDiskAsync(fileThatExists, function (_err, result) {
try {
// assert.isOk(result); // Asserts that object is truthy.
expect(result).toBeTruthy();
// assert.equal(result.main, "lib/index.js");
expect(result.main).toBe("lib/index.js");
done();
}
catch (error) {
done(error);
}
});
});
});
//# sourceMappingURL=filesystem.test.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"filesystem.test.js","sourceRoot":"","sources":["../../src/__tests__/filesystem.test.ts"],"names":[],"mappings":";;AAAA,0CAA4C;AAC5C,2BAA6B;AAE7B,QAAQ,CAAC,YAAY,EAAE;IACrB,IAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,oBAAoB,CAAC,CAAC;IAClE,IAAM,iBAAiB,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,qBAAqB,CAAC,CAAC;IAEtE,EAAE,CAAC,oCAAoC,EAAE;QACvC,IAAM,MAAM,GAAG,UAAU,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC;QACzD,8BAA8B;QAC9B,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,4CAA4C,EAAE;QAC/C,IAAM,MAAM,GAAG,UAAU,CAAC,cAAc,CAAC,iBAAiB,CAAC,CAAC;QAC5D,+BAA+B;QAC/B,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,qCAAqC,EAAE,UAAC,IAAI;QAC7C,UAAU,CAAC,eAAe,CAAC,cAAc,EAAE,UAAC,IAAI,EAAE,MAAM;YACtD,IAAI;gBACF,8BAA8B;gBAC9B,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBAC1B,IAAI,EAAE,CAAC;aACR;YAAC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
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var mapping_entry_1 = require("../mapping-entry");
var path_1 = require("path");
describe("mapping-entry", function () {
it("should change to absolute paths and sort in longest prefix order", function () {
var result = (0, mapping_entry_1.getAbsoluteMappingEntries)("/absolute/base/url", {
"*": ["/foo1", "/foo2"],
"longest/pre/fix/*": ["/foo2/bar"],
"pre/fix/*": ["/foo3"],
}, true);
// assert.deepEqual(result, [
// {
// pattern: "longest/pre/fix/*",
// paths: [join("/absolute", "base", "url", "foo2", "bar")],
// },
// {
// pattern: "pre/fix/*",
// paths: [join("/absolute", "base", "url", "foo3")],
// },
// {
// pattern: "*",
// paths: [
// join("/absolute", "base", "url", "foo1"),
// join("/absolute", "base", "url", "foo2"),
// ],
// },
// ]);
expect(result).toEqual([
{
pattern: "longest/pre/fix/*",
paths: [(0, path_1.join)("/absolute", "base", "url", "foo2", "bar")],
},
{
pattern: "pre/fix/*",
paths: [(0, path_1.join)("/absolute", "base", "url", "foo3")],
},
{
pattern: "*",
paths: [
(0, path_1.join)("/absolute", "base", "url", "foo1"),
(0, path_1.join)("/absolute", "base", "url", "foo2"),
],
},
]);
});
it("should should add a match-all pattern when requested", function () {
var result = (0, mapping_entry_1.getAbsoluteMappingEntries)("/absolute/base/url", {}, true);
// assert.deepEqual(result, [
// {
// pattern: "*",
// paths: [join("/absolute", "base", "url", "*")],
// },
// ]);
expect(result).toEqual([
{
pattern: "*",
paths: [(0, path_1.join)("/absolute", "base", "url", "*")],
},
]);
result = (0, mapping_entry_1.getAbsoluteMappingEntries)("/absolute/base/url", {}, false);
// assert.deepEqual(result, []);
expect(result).toEqual([]);
});
});
//# sourceMappingURL=mapping-entry.test.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"mapping-entry.test.js","sourceRoot":"","sources":["../../src/__tests__/mapping-entry.test.ts"],"names":[],"mappings":";;AAAA,kDAA6D;AAC7D,6BAA4B;AAE5B,QAAQ,CAAC,eAAe,EAAE;IACxB,EAAE,CAAC,kEA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AAC,CAAC,OAAO,CAAC;YACrB;gBACE,OAAO,EAAE,GAAG;gBACZ,KAAK,EAAE,CAAC,IAAA,WAAI,EAAC,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;aAC/C;SACF,CAAC,CAAC;QAEH,MAAM,GAAG,IAAA,yCAAyB,EAAC,oBAAoB,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC;QACpE,gCAAgC;QAChC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}

View file

@ -0,0 +1 @@
export {};

View file

@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var match_path_async_1 = require("../match-path-async");
var Tests = require("./data/match-path-data");
describe("match-path-async", function () {
Tests.tests.forEach(function (t) {
return it(t.name, function (done) {
var matchPath = (0, match_path_async_1.createMatchPathAsync)(t.absoluteBaseUrl, t.paths, t.mainFields, t.addMatchAll);
matchPath(t.requestedModule, function (_path, callback) { return callback(undefined, t.packageJson); }, function (path, callback) {
return callback(undefined, t.existingFiles.indexOf(path) !== -1);
}, t.extensions, function (_err, result) {
// assert.equal(result, t.expectedPath);
expect(result).toBe(t.expectedPath);
done();
});
});
});
});
//# sourceMappingURL=match-path-async.test.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"match-path-async.test.js","sourceRoot":"","sources":["../../src/__tests__/match-path-async.test.ts"],"names":[],"mappings":";;AAAA,wDAA2D;AAC3D,8CAAgD;AAEhD,QAAQ,CAAC,kBAAkB,EAAE;IAC3B,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,UAAC,CAAC;QACpB,OAAA,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,UAAC,IAAI;YACd,IAAM,SAAS,GAAG,IAAA,uCAAoB,EACpC,CAAC,CAAC,eAAe,EACjB,CAAC,CAAC,KAAK,EACP,CAAC,CAAC,UAAU,EACZ,CAAC,CAAC,WAAW,CACd,CAAC;YACF,SAAS,CACP,CAAC,CAAC,eAAe,EACjB,UAAC,KAAK,EAAE,QAAQ,IAAK,OAAA,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAC,WAAW,CAAC,EAAlC,CAAkC,EACvD,UAAC,IAAI,EAAE,QAAQ;gBACb,OAAA,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAC,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;YAAzD,CAAyD,EAC3D,CAAC,CAAC,UAAU,EACZ,UAAC,IAAI,EAAE,MAAM;gBACX,wCAAwC;gBACxC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC;gBACpC,IAAI,EAAE,CAAC;YACT,CAAC,CACF,CAAC;QACJ,CAAC,CAAC;IAnBF,CAmBE,CACH,CAAC;AACJ,CAAC,CAAC,CAAC"}

View file

@ -0,0 +1 @@
export {};

View file

@ -0,0 +1,15 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var match_path_sync_1 = require("../match-path-sync");
var Tests = require("./data/match-path-data");
describe("match-path-sync", function () {
Tests.tests.forEach(function (t) {
return it(t.name, function () {
var matchPath = (0, match_path_sync_1.createMatchPath)(t.absoluteBaseUrl, t.paths, t.mainFields, t.addMatchAll);
var result = matchPath(t.requestedModule, function (_) { return t.packageJson; }, function (name) { return t.existingFiles.indexOf(name) !== -1; }, t.extensions);
// assert.equal(result, t.expectedPath);
expect(result).toBe(t.expectedPath);
});
});
});
//# sourceMappingURL=match-path-sync.test.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"match-path-sync.test.js","sourceRoot":"","sources":["../../src/__tests__/match-path-sync.test.ts"],"names":[],"mappings":";;AAAA,sDAAqD;AACrD,8CAAgD;AAEhD,QAAQ,CAAC,iBAAiB,EAAE;IAC1B,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,UAAC,CAAC;QACpB,OAAA,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE;YACT,IAAM,SAAS,GAAG,IAAA,iCAAe,EAC/B,CAAC,CAAC,eAAe,EACjB,CAAC,CAAC,KAAK,EACP,CAAC,CAAC,UAAU,EACZ,CAAC,CAAC,WAAW,CACd,CAAC;YACF,IAAM,MAAM,GAAG,SAAS,CACtB,CAAC,CAAC,eAAe,EACjB,UAAC,CAAS,IAAK,OAAA,CAAC,CAAC,WAAW,EAAb,CAAa,EAC5B,UAAC,IAAY,IAAK,OAAA,CAAC,CAAC,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAApC,CAAoC,EACtD,CAAC,CAAC,UAAU,CACb,CAAC;YACF,wCAAwC;YACxC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC;QACtC,CAAC,CAAC;IAfF,CAeE,CACH,CAAC;AACJ,CAAC,CAAC,CAAC"}

View file

@ -0,0 +1 @@
export {};

View file

@ -0,0 +1,175 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var try_path_1 = require("../try-path");
var path_1 = require("path");
describe("mapping-entry", function () {
var abosolutePathMappings = [
{
pattern: "longest/pre/fix/*",
paths: [(0, path_1.join)("/absolute", "base", "url", "foo2", "bar")],
},
{ pattern: "pre/fix/*", paths: [(0, path_1.join)("/absolute", "base", "url", "foo3")] },
{ pattern: "*", paths: [(0, path_1.join)("/absolute", "base", "url", "foo1")] },
];
var abosolutePathMappingsStarstWithSlash = [
{
pattern: "/opt/*",
paths: [(0, path_1.join)("/absolute", "src", "aws-layer")],
},
{
pattern: "*",
paths: [(0, path_1.join)("/absolute", "src")],
},
];
it("should return no paths for relative requested module", function () {
var result = (0, try_path_1.getPathsToTry)([".ts", "tsx"], abosolutePathMappings, "./requested-module");
// assert.deepEqual(result, undefined);
expect(result).toBeUndefined();
});
it("should return no paths if no pattern match the requested module", function () {
var result = (0, try_path_1.getPathsToTry)([".ts", "tsx"], [
{
pattern: "longest/pre/fix/*",
paths: [(0, path_1.join)("/absolute", "base", "url", "foo2", "bar")],
},
{
pattern: "pre/fix/*",
paths: [(0, path_1.join)("/absolute", "base", "url", "foo3")],
},
], "requested-module");
expect(result).toBeUndefined();
});
it("should get all paths that matches requested module", function () {
var result = (0, try_path_1.getPathsToTry)([".ts", ".tsx"], abosolutePathMappings, "longest/pre/fix/requested-module");
// assert.deepEqual(result, [
// // "longest/pre/fix/*"
// { type: "file", path: join("/absolute", "base", "url", "foo2", "bar") },
// {
// type: "extension",
// path: join("/absolute", "base", "url", "foo2", "bar.ts"),
// },
// {
// type: "extension",
// path: join("/absolute", "base", "url", "foo2", "bar.tsx"),
// },
// {
// type: "package",
// path: join("/absolute", "base", "url", "foo2", "bar", "package.json"),
// },
// {
// type: "index",
// path: join("/absolute", "base", "url", "foo2", "bar", "index.ts"),
// },
// {
// type: "index",
// path: join("/absolute", "base", "url", "foo2", "bar", "index.tsx"),
// },
// // "*"
// { type: "file", path: join("/absolute", "base", "url", "foo1") },
// { type: "extension", path: join("/absolute", "base", "url", "foo1.ts") },
// { type: "extension", path: join("/absolute", "base", "url", "foo1.tsx") },
// {
// type: "package",
// path: join("/absolute", "base", "url", "foo1", "package.json"),
// },
// {
// type: "index",
// path: join("/absolute", "base", "url", "foo1", "index.ts"),
// },
// {
// type: "index",
// path: join("/absolute", "base", "url", "foo1", "index.tsx"),
// },
// ]);
expect(result).toEqual([
// "longest/pre/fix/*"
{ type: "file", path: (0, path_1.join)("/absolute", "base", "url", "foo2", "bar") },
{
type: "extension",
path: (0, path_1.join)("/absolute", "base", "url", "foo2", "bar.ts"),
},
{
type: "extension",
path: (0, path_1.join)("/absolute", "base", "url", "foo2", "bar.tsx"),
},
{
type: "package",
path: (0, path_1.join)("/absolute", "base", "url", "foo2", "bar", "package.json"),
},
{
type: "index",
path: (0, path_1.join)("/absolute", "base", "url", "foo2", "bar", "index.ts"),
},
{
type: "index",
path: (0, path_1.join)("/absolute", "base", "url", "foo2", "bar", "index.tsx"),
},
// "*"
{ type: "file", path: (0, path_1.join)("/absolute", "base", "url", "foo1") },
{ type: "extension", path: (0, path_1.join)("/absolute", "base", "url", "foo1.ts") },
{ type: "extension", path: (0, path_1.join)("/absolute", "base", "url", "foo1.tsx") },
{
type: "package",
path: (0, path_1.join)("/absolute", "base", "url", "foo1", "package.json"),
},
{
type: "index",
path: (0, path_1.join)("/absolute", "base", "url", "foo1", "index.ts"),
},
{
type: "index",
path: (0, path_1.join)("/absolute", "base", "url", "foo1", "index.tsx"),
},
]);
});
it("should resolve paths starting with a slash", function () {
var result = (0, try_path_1.getPathsToTry)([".ts"], abosolutePathMappingsStarstWithSlash, "/opt/utils");
expect(result).toEqual([
// "opt/*"
{
path: (0, path_1.join)("/absolute", "src", "aws-layer"),
type: "file",
},
{
path: (0, path_1.join)("/absolute", "src", "aws-layer.ts"),
type: "extension",
},
{
path: (0, path_1.join)("/absolute", "src", "aws-layer", "package.json"),
type: "package",
},
{
path: (0, path_1.join)("/absolute", "src", "aws-layer", "index.ts"),
type: "index",
},
// "*"
{
path: (0, path_1.join)("/absolute", "src"),
type: "file",
},
{
path: (0, path_1.join)("/absolute", "src.ts"),
type: "extension",
},
{
path: (0, path_1.join)("/absolute", "src", "package.json"),
type: "package",
},
{
path: (0, path_1.join)("/absolute", "src", "index.ts"),
type: "index",
},
]);
});
});
// describe("match-star", () => {
// it("should match star in last position", () => {
// const result = matchStar("lib/*", "lib/mylib");
// assert.equal(result, "mylib");
// });
// it("should match star in first position", () => {
// const result = matchStar("*/lib", "mylib/lib");
// assert.equal(result, "mylib");
// });
// });
//# sourceMappingURL=try-path.test.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"try-path.test.js","sourceRoot":"","sources":["../../src/__tests__/try-path.test.ts"],"names":[],"mappings":";;AAAA,wCAA4C;AAC5C,6BAA4B;AAE5B,QAAQ,CAAC,eAAe,EAAE;IACxB,IAAM,qBAAqB,GAAG;QAC5B;YACE,OAAO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jC,qDAAqD;AACrD,sDAAsD;AACtD,qCAAqC;AACrC,QAAQ;AACR,sDAAsD;AACtD,sDAAsD;AACtD,qCAAqC;AACrC,QAAQ;AACR,MAAM"}

View file

@ -0,0 +1 @@
export {};

View file

@ -0,0 +1,246 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tsconfig_loader_1 = require("../tsconfig-loader");
var path_1 = require("path");
describe("tsconfig-loader", function () {
it("should find tsconfig in cwd", function () {
var result = (0, tsconfig_loader_1.tsConfigLoader)({
cwd: "/foo/bar",
getEnv: function (_) { return undefined; },
loadSync: function (cwd) {
return {
tsConfigPath: "".concat(cwd, "/tsconfig.json"),
baseUrl: "./",
paths: {},
};
},
});
// assert.equal(result.tsConfigPath, "/foo/bar/tsconfig.json");
expect(result.tsConfigPath).toBe("/foo/bar/tsconfig.json");
});
it("should return loaderResult.tsConfigPath as undefined when not found", function () {
var result = (0, tsconfig_loader_1.tsConfigLoader)({
cwd: "/foo/bar",
getEnv: function (_) { return undefined; },
loadSync: function (_) {
return {
tsConfigPath: undefined,
baseUrl: "./",
paths: {},
};
},
});
// assert.isUndefined(result.tsConfigPath);
expect(result.tsConfigPath).toBeUndefined();
});
it("should use TS_NODE_PROJECT env if exists", function () {
var result = (0, tsconfig_loader_1.tsConfigLoader)({
cwd: "/foo/bar",
getEnv: function (key) {
return key === "TS_NODE_PROJECT" ? "/foo/baz" : undefined;
},
loadSync: function (cwd, fileName) {
if (cwd === "/foo/bar" && fileName === "/foo/baz") {
return {
tsConfigPath: "/foo/baz/tsconfig.json",
baseUrl: "./",
paths: {},
};
}
return {
tsConfigPath: undefined,
baseUrl: "./",
paths: {},
};
},
});
// assert.equal(result.tsConfigPath, "/foo/baz/tsconfig.json");
expect(result.tsConfigPath).toBe("/foo/baz/tsconfig.json");
});
it("should use TS_NODE_BASEURL env if exists", function () {
var result = (0, tsconfig_loader_1.tsConfigLoader)({
cwd: "/foo/bar",
getEnv: function (key) {
return key === "TS_NODE_BASEURL" ? "SOME_BASEURL" : undefined;
},
loadSync: function (_0, _1, baseUrl) {
return {
tsConfigPath: undefined,
baseUrl: baseUrl,
paths: {},
};
},
});
// assert.equal(result.baseUrl, "SOME_BASEURL");
expect(result.baseUrl).toBe("SOME_BASEURL");
});
it("should not use TS_NODE_BASEURL env if it does not exist", function () {
var result = (0, tsconfig_loader_1.tsConfigLoader)({
cwd: "/foo/bar",
getEnv: function (_) {
return undefined;
},
loadSync: function (_0, _1, baseUrl) {
return {
tsConfigPath: undefined,
baseUrl: baseUrl,
paths: {},
};
},
});
// assert.equal(result.baseUrl, undefined);
expect(result.baseUrl).toBeUndefined();
});
});
describe("walkForTsConfig", function () {
it("should find tsconfig in starting directory", function () {
var pathToTsconfig = (0, path_1.join)("/root", "dir1", "tsconfig.json");
var res = (0, tsconfig_loader_1.walkForTsConfig)((0, path_1.join)("/root", "dir1"), function (path) { return path === pathToTsconfig; });
// assert.equal(res, pathToTsconfig);
expect(res).toBe(pathToTsconfig);
});
it("should find tsconfig in parent directory", function () {
var pathToTsconfig = (0, path_1.join)("/root", "tsconfig.json");
var res = (0, tsconfig_loader_1.walkForTsConfig)((0, path_1.join)("/root", "dir1"), function (path) { return path === pathToTsconfig; });
// assert.equal(res, pathToTsconfig);
expect(res).toBe(pathToTsconfig);
});
it("should return undefined when reaching the top", function () {
var res = (0, tsconfig_loader_1.walkForTsConfig)((0, path_1.join)("/root", "dir1", "kalle"), function () { return false; });
// assert.equal(res, undefined);
expect(res).toBeUndefined();
});
});
describe("loadConfig", function () {
it("It should load a config", function () {
var config = { compilerOptions: { baseUrl: "hej" } };
var res = (0, tsconfig_loader_1.loadTsconfig)("/root/dir1/tsconfig.json", function (path) { return path === "/root/dir1/tsconfig.json"; }, function (_) { return JSON.stringify(config); });
// assert.deepEqual(res, config);
expect(res).toStrictEqual(config);
});
it("It should load a config with comments", function () {
var config = { compilerOptions: { baseUrl: "hej" } };
var res = (0, tsconfig_loader_1.loadTsconfig)("/root/dir1/tsconfig.json", function (path) { return path === "/root/dir1/tsconfig.json"; }, function (_) { return "{\n // my comment\n \"compilerOptions\": { \n \"baseUrl\": \"hej\"\n }\n }"; });
// assert.deepEqual(res, config);
expect(res).toStrictEqual(config);
});
it("It should load a config with trailing commas", function () {
var config = { compilerOptions: { baseUrl: "hej" } };
var res = (0, tsconfig_loader_1.loadTsconfig)("/root/dir1/tsconfig.json", function (path) { return path === "/root/dir1/tsconfig.json"; }, function (_) { return "{\n \"compilerOptions\": { \n \"baseUrl\": \"hej\",\n },\n }"; });
// assert.deepEqual(res, config);
expect(res).toStrictEqual(config);
});
it("It should load a config with extends and overwrite all options", function () {
var firstConfig = {
extends: "../base-config.json",
compilerOptions: { baseUrl: "kalle", paths: { foo: ["bar2"] } },
};
var firstConfigPath = (0, path_1.join)("/root", "dir1", "tsconfig.json");
var baseConfig = {
compilerOptions: {
baseUrl: "olle",
paths: { foo: ["bar1"] },
strict: true,
},
};
var baseConfigPath = (0, path_1.join)("/root", "base-config.json");
var res = (0, tsconfig_loader_1.loadTsconfig)((0, path_1.join)("/root", "dir1", "tsconfig.json"), function (path) { return path === firstConfigPath || path === baseConfigPath; }, function (path) {
if (path === firstConfigPath) {
return JSON.stringify(firstConfig);
}
if (path === baseConfigPath) {
return JSON.stringify(baseConfig);
}
return "";
});
// assert.deepEqual(res, {
// extends: "../base-config.json",
// compilerOptions: {
// baseUrl: "kalle",
// paths: { foo: ["bar2"] },
// strict: true,
// },
// });
expect(res).toEqual({
extends: "../base-config.json",
compilerOptions: {
baseUrl: "kalle",
paths: { foo: ["bar2"] },
strict: true,
},
});
});
it("It should load a config with extends from node_modules and overwrite all options", function () {
var firstConfig = {
extends: "my-package/base-config.json",
compilerOptions: { baseUrl: "kalle", paths: { foo: ["bar2"] } },
};
var firstConfigPath = (0, path_1.join)("/root", "dir1", "tsconfig.json");
var baseConfig = {
compilerOptions: {
baseUrl: "olle",
paths: { foo: ["bar1"] },
strict: true,
},
};
var baseConfigPath = (0, path_1.join)("/root", "dir1", "node_modules", "my-package", "base-config.json");
var res = (0, tsconfig_loader_1.loadTsconfig)((0, path_1.join)("/root", "dir1", "tsconfig.json"), function (path) { return path === firstConfigPath || path === baseConfigPath; }, function (path) {
if (path === firstConfigPath) {
return JSON.stringify(firstConfig);
}
if (path === baseConfigPath) {
return JSON.stringify(baseConfig);
}
return "";
});
// assert.deepEqual(res, {
// extends: "my-package/base-config.json",
// compilerOptions: {
// baseUrl: "kalle",
// paths: { foo: ["bar2"] },
// strict: true,
// },
// });
expect(res).toEqual({
extends: "my-package/base-config.json",
compilerOptions: {
baseUrl: "kalle",
paths: { foo: ["bar2"] },
strict: true,
},
});
});
it("Should use baseUrl relative to location of extended tsconfig", function () {
var firstConfig = { compilerOptions: { baseUrl: "." } };
var firstConfigPath = (0, path_1.join)("/root", "first-config.json");
var secondConfig = { extends: "../first-config.json" };
var secondConfigPath = (0, path_1.join)("/root", "dir1", "second-config.json");
var thirdConfig = { extends: "../second-config.json" };
var thirdConfigPath = (0, path_1.join)("/root", "dir1", "dir2", "third-config.json");
var res = (0, tsconfig_loader_1.loadTsconfig)((0, path_1.join)("/root", "dir1", "dir2", "third-config.json"), function (path) {
return path === firstConfigPath ||
path === secondConfigPath ||
path === thirdConfigPath;
}, function (path) {
if (path === firstConfigPath) {
return JSON.stringify(firstConfig);
}
if (path === secondConfigPath) {
return JSON.stringify(secondConfig);
}
if (path === thirdConfigPath) {
return JSON.stringify(thirdConfig);
}
return "";
});
// assert.deepEqual(res, {
// extends: "../second-config.json",
// compilerOptions: { baseUrl: join("..", "..") },
// });
expect(res).toEqual({
extends: "../second-config.json",
compilerOptions: { baseUrl: (0, path_1.join)("..", "..") },
});
});
});
//# sourceMappingURL=tsconfig-loader.test.js.map

File diff suppressed because one or more lines are too long

View file

@ -1,4 +1,4 @@
import * as TsConfigLoader from "./tsconfig-loader";
import * as TsConfigLoader2 from "./tsconfig-loader";
export interface ExplicitParams {
baseUrl: string;
paths: {
@ -7,7 +7,7 @@ export interface ExplicitParams {
mainFields?: Array<string>;
addMatchAll?: boolean;
}
export declare type TsConfigLoader = (params: TsConfigLoader.TsConfigLoaderParams) => TsConfigLoader.TsConfigLoaderResult;
export declare type TsConfigLoader = (params: TsConfigLoader2.TsConfigLoaderParams) => TsConfigLoader2.TsConfigLoaderResult;
export interface ConfigLoaderParams {
cwd: string;
explicitParams?: ExplicitParams;
@ -30,4 +30,4 @@ export interface ConfigLoaderFailResult {
}
export declare type ConfigLoaderResult = ConfigLoaderSuccessResult | ConfigLoaderFailResult;
export declare function loadConfig(cwd?: string): ConfigLoaderResult;
export declare function configLoader({ cwd, explicitParams, tsConfigLoader }: ConfigLoaderParams): ConfigLoaderResult;
export declare function configLoader({ cwd, explicitParams, tsConfigLoader, }: ConfigLoaderParams): ConfigLoaderResult;

View file

@ -1,6 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var TsConfigLoader = require("./tsconfig-loader");
exports.configLoader = exports.loadConfig = void 0;
var TsConfigLoader2 = require("./tsconfig-loader");
var path = require("path");
var options_1 = require("./options");
function loadConfig(cwd) {
@ -9,7 +10,7 @@ function loadConfig(cwd) {
}
exports.loadConfig = loadConfig;
function configLoader(_a) {
var cwd = _a.cwd, explicitParams = _a.explicitParams, _b = _a.tsConfigLoader, tsConfigLoader = _b === void 0 ? TsConfigLoader.tsConfigLoader : _b;
var cwd = _a.cwd, explicitParams = _a.explicitParams, _b = _a.tsConfigLoader, tsConfigLoader = _b === void 0 ? TsConfigLoader2.tsConfigLoader : _b;
if (explicitParams) {
// tslint:disable-next-line:no-shadowed-variable
var absoluteBaseUrl_1 = path.isAbsolute(explicitParams.baseUrl)
@ -22,24 +23,24 @@ function configLoader(_a) {
absoluteBaseUrl: absoluteBaseUrl_1,
paths: explicitParams.paths,
mainFields: explicitParams.mainFields,
addMatchAll: explicitParams.addMatchAll
addMatchAll: explicitParams.addMatchAll,
};
}
// Load tsconfig and create path matching function
var loadResult = tsConfigLoader({
cwd: cwd,
getEnv: function (key) { return process.env[key]; }
getEnv: function (key) { return process.env[key]; },
});
if (!loadResult.tsConfigPath) {
return {
resultType: "failed",
message: "Couldn't find tsconfig.json"
message: "Couldn't find tsconfig.json",
};
}
if (!loadResult.baseUrl) {
return {
resultType: "failed",
message: "Missing baseUrl in compilerOptions"
message: "Missing baseUrl in compilerOptions",
};
}
var tsConfigDir = path.dirname(loadResult.tsConfigPath);
@ -49,7 +50,8 @@ function configLoader(_a) {
configFileAbsolutePath: loadResult.tsConfigPath,
baseUrl: loadResult.baseUrl,
absoluteBaseUrl: absoluteBaseUrl,
paths: loadResult.paths || {}
paths: loadResult.paths || {},
};
}
exports.configLoader = configLoader;
//# sourceMappingURL=config-loader.js.map

1
node_modules/tsconfig-paths/lib/config-loader.js.map generated vendored Normal file
View file

@ -0,0 +1 @@
{"version":3,"file":"config-loader.js","sourceRoot":"","sources":["../src/config-loader.ts"],"names":[],"mappings":";;;AAAA,mDAAqD;AACrD,2BAA6B;AAC7B,qCAAoC;AAsCpC,SAAgB,UAAU,CAAC,GAAyB;IAAzB,oBAAA,EAAA,MAAc,iBAAO,CAAC,GAAG;IAClD,OAAO,YAAY,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC;AACpC,CAAC;AAFD,gCAEC;AAED,SAAgB,YAAY,CAAC,EAIR;QAHnB,GAAG,SAAA,EACH,cAAc,oBAAA,EACd,sBAA+C,EAA/C,cAAc,mBAAG,eAAe,CAAC,cAAc,KAAA;IAE/C,IAAI,cAAc,EAAE;QAClB,gDAAgD;QAChD,IAAM,iBAAe,GAAG,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,OAAO,CAAC;YAC7D,CAAC,CAAC,cAAc,CAAC,OAAO;YACxB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC;QAE3C,OAAO;YACL,UAAU,EAAE,SAAS;YACrB,sBAAsB,EAAE,EAAE;YAC1B,OAAO,EAAE,cAAc,CAAC,OAAO;YAC/B,eAAe,mBAAA;YACf,KAAK,EAAE,cAAc,CAAC,KAAK;YAC3B,UAAU,EAAE,cAAc,CAAC,UAAU;YACrC,WAAW,EAAE,cAAc,CAAC,WAAW;SACxC,CAAC;KACH;IAED,kDAAkD;IAClD,IAAM,UAAU,GAAG,cAAc,CAAC;QAChC,GAAG,KAAA;QACH,MAAM,EAAE,UAAC,GAAW,IAAK,OAAA,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAhB,CAAgB;KAC1C,CAAC,CAAC;IAEH,IAAI,CAAC,UAAU,CAAC,YAAY,EAAE;QAC5B,OAAO;YACL,UAAU,EAAE,QAAQ;YACpB,OAAO,EAAE,6BAA6B;SACvC,CAAC;KACH;IAED,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE;QACvB,OAAO;YACL,UAAU,EAAE,QAAQ;YACpB,OAAO,EAAE,oCAAoC;SAC9C,CAAC;KACH;IAED,IAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;IAC1D,IAAM,eAAe,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC;IAEnE,OAAO;QACL,UAAU,EAAE,SAAS;QACrB,sBAAsB,EAAE,UAAU,CAAC,YAAY;QAC/C,OAAO,EAAE,UAAU,CAAC,OAAO;QAC3B,eAAe,iBAAA;QACf,KAAK,EAAE,UAAU,CAAC,KAAK,IAAI,EAAE;KAC9B,CAAC;AACJ,CAAC;AApDD,oCAoDC"}

View file

@ -1,5 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.removeExtension = exports.fileExistsAsync = exports.readJsonFromDiskAsync = exports.readJsonFromDiskSync = exports.fileExistsSync = void 0;
var fs = require("fs");
function fileExistsSync(path) {
try {
@ -51,3 +52,4 @@ function removeExtension(path) {
return path.substring(0, path.lastIndexOf(".")) || path;
}
exports.removeExtension = removeExtension;
//# sourceMappingURL=filesystem.js.map

1
node_modules/tsconfig-paths/lib/filesystem.js.map generated vendored Normal file
View file

@ -0,0 +1 @@
{"version":3,"file":"filesystem.js","sourceRoot":"","sources":["../src/filesystem.ts"],"names":[],"mappings":";;;AAAA,uBAAyB;AAkCzB,SAAgB,cAAc,CAAC,IAAY;IACzC,IAAI;QACF,IAAM,KAAK,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAChC,OAAO,KAAK,CAAC,MAAM,EAAE,CAAC;KACvB;IAAC,OAAO,GAAG,EAAE;QACZ,sCAAsC;QACtC,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AARD,wCAQC;AAED;;;GAGG;AACH,kCAAkC;AAClC,SAAgB,oBAAoB,CAAC,eAAuB;IAC1D,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE;QACnC,OAAO,SAAS,CAAC;KAClB;IACD,OAAO,OAAO,CAAC,eAAe,CAAC,CAAC;AAClC,CAAC;AALD,oDAKC;AAED,SAAgB,qBAAqB,CACnC,IAAY;AACZ,kCAAkC;AAClC,QAA8C;IAE9C,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,UAAC,GAAG,EAAE,MAAM;QACpC,sCAAsC;QACtC,IAAI,GAAG,IAAI,CAAC,MAAM,EAAE;YAClB,OAAO,QAAQ,EAAE,CAAC;SACnB;QACD,IAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAChC,OAAO,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;AACL,CAAC;AAbD,sDAaC;AAED,SAAgB,eAAe,CAC7B,KAAa,EACb,SAAkD;IAElD,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,UAAC,GAAU,EAAE,KAAe;QACzC,IAAI,GAAG,EAAE;YACP,sCAAsC;YACtC,OAAO,SAAS,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;SACpC;QACD,SAAS,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;AACL,CAAC;AAXD,0CAWC;AAED,SAAgB,eAAe,CAAC,IAAY;IAC1C,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC;AAC1D,CAAC;AAFD,0CAEC"}

View file

@ -1,5 +1,5 @@
export { createMatchPath, matchFromAbsolutePaths, MatchPath } from "./match-path-sync";
export { createMatchPathAsync, matchFromAbsolutePathsAsync, MatchPathAsync } from "./match-path-async";
export { createMatchPath, matchFromAbsolutePaths, MatchPath, } from "./match-path-sync";
export { createMatchPathAsync, matchFromAbsolutePathsAsync, MatchPathAsync, } from "./match-path-async";
export { register } from "./register";
export { loadConfig, ConfigLoaderResult, ConfigLoaderSuccessResult, ConfigLoaderFailResult } from "./config-loader";
export { ReadJsonSync, ReadJsonAsync, FileExistsSync, FileExistsAsync } from "./filesystem";
export { loadConfig, ConfigLoaderResult, ConfigLoaderSuccessResult, ConfigLoaderFailResult, } from "./config-loader";
export { ReadJsonSync, ReadJsonAsync, FileExistsSync, FileExistsAsync, } from "./filesystem";

View file

@ -1,13 +1,15 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.loadConfig = exports.register = exports.matchFromAbsolutePathsAsync = exports.createMatchPathAsync = exports.matchFromAbsolutePaths = exports.createMatchPath = void 0;
// register is used from register.js in root dir
var match_path_sync_1 = require("./match-path-sync");
exports.createMatchPath = match_path_sync_1.createMatchPath;
exports.matchFromAbsolutePaths = match_path_sync_1.matchFromAbsolutePaths;
Object.defineProperty(exports, "createMatchPath", { enumerable: true, get: function () { return match_path_sync_1.createMatchPath; } });
Object.defineProperty(exports, "matchFromAbsolutePaths", { enumerable: true, get: function () { return match_path_sync_1.matchFromAbsolutePaths; } });
var match_path_async_1 = require("./match-path-async");
exports.createMatchPathAsync = match_path_async_1.createMatchPathAsync;
exports.matchFromAbsolutePathsAsync = match_path_async_1.matchFromAbsolutePathsAsync;
Object.defineProperty(exports, "createMatchPathAsync", { enumerable: true, get: function () { return match_path_async_1.createMatchPathAsync; } });
Object.defineProperty(exports, "matchFromAbsolutePathsAsync", { enumerable: true, get: function () { return match_path_async_1.matchFromAbsolutePathsAsync; } });
var register_1 = require("./register");
exports.register = register_1.register;
Object.defineProperty(exports, "register", { enumerable: true, get: function () { return register_1.register; } });
var config_loader_1 = require("./config-loader");
exports.loadConfig = config_loader_1.loadConfig;
Object.defineProperty(exports, "loadConfig", { enumerable: true, get: function () { return config_loader_1.loadConfig; } });
//# sourceMappingURL=index.js.map

1
node_modules/tsconfig-paths/lib/index.js.map generated vendored Normal file
View file

@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,gDAAgD;AAChD,qDAI2B;AAHzB,kHAAA,eAAe,OAAA;AACf,yHAAA,sBAAsB,OAAA;AAGxB,uDAI4B;AAH1B,wHAAA,oBAAoB,OAAA;AACpB,+HAAA,2BAA2B,OAAA;AAG7B,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA;AACjB,iDAKyB;AAJvB,2GAAA,UAAU,OAAA"}

View file

@ -1,5 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAbsoluteMappingEntries = void 0;
var path = require("path");
/**
* Converts an absolute baseUrl and paths to an array of absolute mapping entries.
@ -13,7 +14,7 @@ var path = require("path");
function getAbsoluteMappingEntries(absoluteBaseUrl, paths, addMatchAll) {
// Resolve all paths to absolute form once here, and sort them by
// longest prefix once here, this saves time on each request later.
// We need to put them in an array to preseve the sorting order.
// We need to put them in an array to preserve the sorting order.
var sortedKeys = sortByLongestPrefix(Object.keys(paths));
var absolutePaths = [];
for (var _i = 0, sortedKeys_1 = sortedKeys; _i < sortedKeys_1.length; _i++) {
@ -22,7 +23,7 @@ function getAbsoluteMappingEntries(absoluteBaseUrl, paths, addMatchAll) {
pattern: key,
paths: paths[key].map(function (pathToResolve) {
return path.join(absoluteBaseUrl, pathToResolve);
})
}),
});
}
// If there is no match-all path specified in the paths section of tsconfig, then try to match
@ -30,7 +31,7 @@ function getAbsoluteMappingEntries(absoluteBaseUrl, paths, addMatchAll) {
if (!paths["*"] && addMatchAll) {
absolutePaths.push({
pattern: "*",
paths: [absoluteBaseUrl.replace(/\/$/, "") + "/*"]
paths: ["".concat(absoluteBaseUrl.replace(/\/$/, ""), "/*")],
});
}
return absolutePaths;
@ -49,3 +50,4 @@ function getPrefixLength(pattern) {
var prefixLength = pattern.indexOf("*");
return pattern.substr(0, prefixLength).length;
}
//# sourceMappingURL=mapping-entry.js.map

1
node_modules/tsconfig-paths/lib/mapping-entry.js.map generated vendored Normal file
View file

@ -0,0 +1 @@
{"version":3,"file":"mapping-entry.js","sourceRoot":"","sources":["../src/mapping-entry.ts"],"names":[],"mappings":";;;AAAA,2BAA6B;AAW7B;;;;;;;;GAQG;AACH,SAAgB,yBAAyB,CACvC,eAAuB,EACvB,KAAY,EACZ,WAAoB;IAEpB,iEAAiE;IACjE,mEAAmE;IACnE,iEAAiE;IACjE,IAAM,UAAU,GAAG,mBAAmB,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAC3D,IAAM,aAAa,GAAwB,EAAE,CAAC;IAC9C,KAAkB,UAAU,EAAV,yBAAU,EAAV,wBAAU,EAAV,IAAU,EAAE;QAAzB,IAAM,GAAG,mBAAA;QACZ,aAAa,CAAC,IAAI,CAAC;YACjB,OAAO,EAAE,GAAG;YACZ,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,UAAC,aAAa;gBAClC,OAAA,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,aAAa,CAAC;YAAzC,CAAyC,CAC1C;SACF,CAAC,CAAC;KACJ;IACD,8FAA8F;IAC9F,+DAA+D;IAC/D,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,WAAW,EAAE;QAC9B,aAAa,CAAC,IAAI,CAAC;YACjB,OAAO,EAAE,GAAG;YACZ,KAAK,EAAE,CAAC,UAAG,eAAe,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,OAAI,CAAC;SACnD,CAAC,CAAC;KACJ;IAED,OAAO,aAAa,CAAC;AACvB,CAAC;AA5BD,8DA4BC;AAED;;;GAGG;AACH,SAAS,mBAAmB,CAAC,GAAkB;IAC7C,OAAO,GAAG;SACP,MAAM,EAAE;SACR,IAAI,CAAC,UAAC,CAAS,EAAE,CAAS,IAAK,OAAA,eAAe,CAAC,CAAC,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,EAAvC,CAAuC,CAAC,CAAC;AAC7E,CAAC;AAED,SAAS,eAAe,CAAC,OAAe;IACtC,IAAM,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC1C,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,MAAM,CAAC;AAChD,CAAC"}

View file

@ -18,4 +18,4 @@ export declare function createMatchPathAsync(absoluteBaseUrl: string, paths: {
/**
* See the sync version for docs.
*/
export declare function matchFromAbsolutePathsAsync(absolutePathMappings: ReadonlyArray<MappingEntry.MappingEntry>, requestedModule: string, readJson: Filesystem.ReadJsonAsync | undefined, fileExists: Filesystem.FileExistsAsync | undefined, extensions: ReadonlyArray<string> | undefined, callback: MatchPathAsyncCallback, mainFields?: string[]): void;
export declare function matchFromAbsolutePathsAsync(absolutePathMappings: ReadonlyArray<MappingEntry.MappingEntry>, requestedModule: string, readJson: Filesystem.ReadJsonAsync | undefined, fileExists: Filesystem.FileExistsAsync | undefined, extensions: readonly string[] | undefined, callback: MatchPathAsyncCallback, mainFields?: string[]): void;

View file

@ -1,5 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.matchFromAbsolutePathsAsync = exports.createMatchPathAsync = void 0;
var path = require("path");
var TryPath = require("./try-path");
var MappingEntry = require("./mapping-entry");
@ -68,7 +69,6 @@ function findFirstExistingPath(tryPaths, readJson, fileExists, doneCallback, ind
return doneCallback(err);
}
if (exists) {
// Not sure why we don't just return the full path? Why strip it?
return doneCallback(undefined, TryPath.getStrippedPath(tryPath));
}
if (index === tryPaths.length - 1) {
@ -89,8 +89,7 @@ function findFirstExistingPath(tryPaths, readJson, fileExists, doneCallback, ind
return doneCallback(mainFieldErr);
}
if (mainFieldMappedFile) {
// Not sure why we don't just return the full path? Why strip it?
return doneCallback(undefined, Filesystem.removeExtension(mainFieldMappedFile));
return doneCallback(undefined, mainFieldMappedFile);
}
// No field in package json was a valid option. Continue with the next path.
return findFirstExistingPath(tryPaths, readJson, fileExists, doneCallback, index + 1, mainFields);
@ -111,3 +110,4 @@ function findFirstExistingPath(tryPaths, readJson, fileExists, doneCallback, ind
TryPath.exhaustiveTypeException(tryPath.type);
}
}
//# sourceMappingURL=match-path-async.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"match-path-async.js","sourceRoot":"","sources":["../src/match-path-async.ts"],"names":[],"mappings":";;;AAAA,2BAA6B;AAC7B,oCAAsC;AACtC,8CAAgD;AAChD,yCAA2C;AAmB3C;;GAEG;AACH,SAAgB,oBAAoB,CAClC,eAAuB,EACvB,KAAuC,EACvC,UAA+B,EAC/B,WAA2B;IAD3B,2BAAA,EAAA,cAAwB,MAAM,CAAC;IAC/B,4BAAA,EAAA,kBAA2B;IAE3B,IAAM,aAAa,GAAG,YAAY,CAAC,yBAAyB,CAC1D,eAAe,EACf,KAAK,EACL,WAAW,CACZ,CAAC;IAEF,OAAO,UACL,eAAuB,EACvB,QAA8C,EAC9C,UAAkD,EAClD,UAA6C,EAC7C,QAAgC;QAEhC,OAAA,2BAA2B,CACzB,aAAa,EACb,eAAe,EACf,QAAQ,EACR,UAAU,EACV,UAAU,EACV,QAAQ,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AAC,CAAC,CAAC;KACJ;SAAM,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,EAAE;QACrC,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,UAAC,GAAG,EAAE,WAAW;YACtC,IAAI,GAAG,EAAE;gBACP,OAAO,YAAY,CAAC,GAAG,CAAC,CAAC;aAC1B;YACD,IAAI,WAAW,EAAE;gBACf,OAAO,oCAAoC,CACzC,WAAW,EACX,UAAU,EACV,OAAO,CAAC,IAAI,EACZ,UAAU,EACV,UAAC,YAAoB,EAAE,mBAA4B;oBACjD,IAAI,YAAY,EAAE;wBAChB,OAAO,YAAY,CAAC,YAAY,CAAC,CAAC;qBACnC;oBACD,IAAI,mBAAmB,EAAE;wBACvB,OAAO,YAAY,CAAC,SAAS,EAAE,mBAAmB,CAAC,CAAC;qBACrD;oBAED,4EAA4E;oBAC5E,OAAO,qBAAqB,CAC1B,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,YAAY,EACZ,KAAK,GAAG,CAAC,EACT,UAAU,CACX,CAAC;gBACJ,CAAC,CACF,CAAC;aACH;YAED,wFAAwF;YACxF,8FAA8F;YAC9F,4EAA4E;YAC5E,EAAE;YACF,0CAA0C;YAC1C,qEAAqE;YACrE,EAAE;YACF,8BAA8B;YAC9B,OAAO,qBAAqB,CAC1B,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,YAAY,EACZ,KAAK,GAAG,CAAC,EACT,UAAU,CACX,CAAC;QACJ,CAAC,CAAC,CAAC;KACJ;SAAM;QACL,OAAO,CAAC,uBAAuB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;KAC/C;AACH,CAAC"}

View file

@ -22,7 +22,7 @@ export declare function createMatchPath(absoluteBaseUrl: string, paths: {
* @param absolutePathMappings The paths to try as specified in tsconfig but resolved to absolute form.
* @param requestedModule The required module name.
* @param readJson Function that can read json from a path (useful for testing).
* @param fileExists Function that checks for existance of a file at a path (useful for testing).
* @param fileExists Function that checks for existence of a file at a path (useful for testing).
* @param extensions File extensions to probe for (useful for testing).
* @param mainFields A list of package.json field names to try when resolving module files.
* @returns the found path, or undefined if no path was found.

View file

@ -1,5 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.matchFromAbsolutePaths = exports.createMatchPath = void 0;
var path = require("path");
var Filesystem = require("./filesystem");
var MappingEntry = require("./mapping-entry");
@ -26,7 +27,7 @@ exports.createMatchPath = createMatchPath;
* @param absolutePathMappings The paths to try as specified in tsconfig but resolved to absolute form.
* @param requestedModule The required module name.
* @param readJson Function that can read json from a path (useful for testing).
* @param fileExists Function that checks for existance of a file at a path (useful for testing).
* @param fileExists Function that checks for existence of a file at a path (useful for testing).
* @param extensions File extensions to probe for (useful for testing).
* @param mainFields A list of package.json field names to try when resolving module files.
* @returns the found path, or undefined if no path was found.
@ -65,7 +66,6 @@ function findFirstExistingPath(tryPaths, readJson, fileExists, mainFields) {
tryPath.type === "extension" ||
tryPath.type === "index") {
if (fileExists(tryPath.path)) {
// Not sure why we don't just return the full path? Why strip it?
return TryPath.getStrippedPath(tryPath);
}
}
@ -74,8 +74,7 @@ function findFirstExistingPath(tryPaths, readJson, fileExists, mainFields) {
if (packageJson) {
var mainFieldMappedFile = findFirstExistingMainFieldMappedFile(packageJson, mainFields, tryPath.path, fileExists);
if (mainFieldMappedFile) {
// Not sure why we don't just return the full path? Why strip it?
return Filesystem.removeExtension(mainFieldMappedFile);
return mainFieldMappedFile;
}
}
}
@ -85,3 +84,4 @@ function findFirstExistingPath(tryPaths, readJson, fileExists, mainFields) {
}
return undefined;
}
//# sourceMappingURL=match-path-sync.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"match-path-sync.js","sourceRoot":"","sources":["../src/match-path-sync.ts"],"names":[],"mappings":";;;AAAA,2BAA6B;AAC7B,yCAA2C;AAC3C,8CAAgD;AAChD,oCAAsC;AActC;;;;;;;GAOG;AACH,SAAgB,eAAe,CAC7B,eAAuB,EACvB,KAAuC,EACvC,UAA+B,EAC/B,WAA2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AAC"}

View file

@ -1,13 +1,15 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.options = void 0;
var minimist = require("minimist");
var argv = minimist(process.argv.slice(2), {
string: ["project"],
alias: {
project: ["P"]
}
project: ["P"],
},
});
var project = argv && argv.project;
exports.options = {
cwd: project || process.cwd()
cwd: project || process.cwd(),
};
//# sourceMappingURL=options.js.map

1
node_modules/tsconfig-paths/lib/options.js.map generated vendored Normal file
View file

@ -0,0 +1 @@
{"version":3,"file":"options.js","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":";;;AAAA,mCAAqC;AAErC,IAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;IAC3C,MAAM,EAAE,CAAC,SAAS,CAAC;IACnB,KAAK,EAAE;QACL,OAAO,EAAE,CAAC,GAAG,CAAC;KACf;CACF,CAAC,CAAC;AAEH,IAAM,OAAO,GAAG,IAAI,IAAI,IAAI,CAAC,OAAO,CAAC;AAMxB,QAAA,OAAO,GAAY;IAC9B,GAAG,EAAE,OAAO,IAAI,OAAO,CAAC,GAAG,EAAE;CAC9B,CAAC"}

View file

@ -1,5 +1,15 @@
"use strict";
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.register = void 0;
var match_path_sync_1 = require("./match-path-sync");
var config_loader_1 = require("./config-loader");
var options_1 = require("./options");
@ -32,7 +42,7 @@ function getCoreModules(builtinModules) {
"util",
"v8",
"vm",
"zlib"
"zlib",
];
var coreModules = {};
for (var _i = 0, builtinModules_1 = builtinModules; _i < builtinModules_1.length; _i++) {
@ -46,15 +56,15 @@ function getCoreModules(builtinModules) {
* Returns a function to undo paths registration.
*/
function register(explicitParams) {
var configLoaderResult = config_loader_1.configLoader({
var configLoaderResult = (0, config_loader_1.configLoader)({
cwd: options_1.options.cwd,
explicitParams: explicitParams
explicitParams: explicitParams,
});
if (configLoaderResult.resultType === "failed") {
console.warn(configLoaderResult.message + ". tsconfig-paths will be skipped");
console.warn("".concat(configLoaderResult.message, ". tsconfig-paths will be skipped"));
return noOp;
}
var matchPath = match_path_sync_1.createMatchPath(configLoaderResult.absoluteBaseUrl, configLoaderResult.paths, configLoaderResult.mainFields, configLoaderResult.addMatchAll);
var matchPath = (0, match_path_sync_1.createMatchPath)(configLoaderResult.absoluteBaseUrl, configLoaderResult.paths, configLoaderResult.mainFields, configLoaderResult.addMatchAll);
// Patch node's module loading
// tslint:disable-next-line:no-require-imports variable-name
var Module = require("module");
@ -66,7 +76,7 @@ function register(explicitParams) {
if (!isCoreModule) {
var found = matchPath(request);
if (found) {
var modifiedArguments = [found].concat([].slice.call(arguments, 1)); // Passes all arguments. Even those that is not specified above.
var modifiedArguments = __spreadArray([found], [].slice.call(arguments, 1), true); // Passes all arguments. Even those that is not specified above.
// tslint:disable-next-line:no-invalid-this
return originalResolveFilename.apply(this, modifiedArguments);
}
@ -80,3 +90,4 @@ function register(explicitParams) {
};
}
exports.register = register;
//# sourceMappingURL=register.js.map

1
node_modules/tsconfig-paths/lib/register.js.map generated vendored Normal file
View file

@ -0,0 +1 @@
{"version":3,"file":"register.js","sourceRoot":"","sources":["../src/register.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAAoD;AACpD,iDAA+D;AAC/D,qCAAoC;AAEpC,IAAM,IAAI,GAAG,cAAY,OAAA,KAAK,CAAC,EAAN,CAAM,CAAC;AAEhC,SAAS,cAAc,CACrB,cAAoC;IAEpC,cAAc,GAAG,cAAc,IAAI;QACjC,QAAQ;QACR,QAAQ;QACR,eAAe;QACf,SAAS;QACT,QAAQ;QACR,OAAO;QACP,KAAK;QACL,QAAQ;QACR,QAAQ;QACR,IAAI;Q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,CAAC,CAAC;QACzD,IAAI,CAAC,YAAY,EAAE;YACjB,IAAM,KAAK,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC;YACjC,IAAI,KAAK,EAAE;gBACT,IAAM,iBAAiB,kBAAI,KAAK,GAAK,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,OAAC,CAAC,CAAC,gEAAgE;gBACnI,2CAA2C;gBAC3C,OAAO,uBAAuB,CAAC,KAAK,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAC;aAC/D;SACF;QACD,2CAA2C;QAC3C,OAAO,uBAAuB,CAAC,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IACxD,CAAC,CAAC;IAEF,OAAO;QACL,kDAAkD;QAClD,MAAM,CAAC,gBAAgB,GAAG,uBAAuB,CAAC;IACpD,CAAC,CAAC;AACJ,CAAC;AA7CD,4BA6CC"}

View file

@ -1,5 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.exhaustiveTypeException = exports.getStrippedPath = exports.getPathsToTry = void 0;
var path = require("path");
var path_1 = require("path");
var filesystem_1 = require("./filesystem");
@ -11,10 +12,7 @@ var filesystem_1 = require("./filesystem");
* 4. Check for files named as request ending in "index" with any of the extensions.
*/
function getPathsToTry(extensions, absolutePathMappings, requestedModule) {
if (!absolutePathMappings ||
!requestedModule ||
requestedModule[0] === "." ||
requestedModule[0] === path.sep) {
if (!absolutePathMappings || !requestedModule || requestedModule[0] === ".") {
return undefined;
}
var pathsToTry = [];
@ -30,7 +28,7 @@ function getPathsToTry(extensions, absolutePathMappings, requestedModule) {
pathsToTry.push.apply(pathsToTry, extensions.map(function (e) { return ({ type: "extension", path: physicalPath + e }); }));
pathsToTry.push({
type: "package",
path: path.join(physicalPath, "/package.json")
path: path.join(physicalPath, "/package.json"),
});
var indexPath = path.join(physicalPath, "/index");
pathsToTry.push.apply(pathsToTry, extensions.map(function (e) { return ({ type: "index", path: indexPath + e }); }));
@ -47,18 +45,18 @@ exports.getPathsToTry = getPathsToTry;
// Not sure why we don't just return the full found path?
function getStrippedPath(tryPath) {
return tryPath.type === "index"
? path_1.dirname(tryPath.path)
? (0, path_1.dirname)(tryPath.path)
: tryPath.type === "file"
? tryPath.path
: tryPath.type === "extension"
? filesystem_1.removeExtension(tryPath.path)
? (0, filesystem_1.removeExtension)(tryPath.path)
: tryPath.type === "package"
? tryPath.path
: exhaustiveTypeException(tryPath.type);
}
exports.getStrippedPath = getStrippedPath;
function exhaustiveTypeException(check) {
throw new Error("Unknown type " + check);
throw new Error("Unknown type ".concat(check));
}
exports.exhaustiveTypeException = exhaustiveTypeException;
/**
@ -89,3 +87,4 @@ function matchStar(pattern, search) {
}
return search.substr(star, search.length - part2.length);
}
//# sourceMappingURL=try-path.js.map

1
node_modules/tsconfig-paths/lib/try-path.js.map generated vendored Normal file
View file

@ -0,0 +1 @@
{"version":3,"file":"try-path.js","sourceRoot":"","sources":["../src/try-path.ts"],"names":[],"mappings":";;;AAAA,2BAA6B;AAE7B,6BAA+B;AAC/B,2CAA+C;AAO/C;;;;;;GAMG;AACH,SAAgB,aAAa,CAC3B,UAAiC,EACjC,oBAAiD,EACjD,eAAuB;IAEvB,IAAI,CAAC,oBAAoB,IAAI,CAAC,eAAe,IAAI,eAAe,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;QAC3E,OAAO,SAAS,CAAC;KAClB;IAED,IAAM,UAAU,GAAmB,EAAE,CAAC;IACtC,KAAoB,UAAoB,EAApB,6CAAoB,EAApB,kCAAoB,EAApB,IAAoB,EAAE;QAArC,IAAM,KAAK,6BAAA;QACd,IAAM,SAAS,GACb,KAAK,CAAC,OAAO,KAAK,eAAe;YAC/B,CAAC,CAAC,EAAE;YACJ,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;QAChD,IAAI,SAAS,KAAK,SAAS,EAAE;oCAChB,mBAAmB;gBAC5B,IAAM,YAAY,GAAG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AM,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;AAC3D,CAAC"}

View file

@ -21,8 +21,8 @@ export interface TsConfigLoaderResult {
export interface TsConfigLoaderParams {
getEnv: (key: string) => string | undefined;
cwd: string;
loadSync?(cwd: string, filename?: string): TsConfigLoaderResult;
loadSync?(cwd: string, filename?: string, baseUrl?: string): TsConfigLoaderResult;
}
export declare function tsConfigLoader({ getEnv, cwd, loadSync }: TsConfigLoaderParams): TsConfigLoaderResult;
export declare function tsConfigLoader({ getEnv, cwd, loadSync, }: TsConfigLoaderParams): TsConfigLoaderResult;
export declare function walkForTsConfig(directory: string, existsSync?: (path: string) => boolean): string | undefined;
export declare function loadTsconfig(configFilePath: string, existsSync?: (path: string) => boolean, readFileSync?: (filename: string) => string): Tsconfig | undefined;

View file

@ -1,13 +1,17 @@
"use strict";
var __assign = (this && this.__assign) || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.loadTsconfig = exports.walkForTsConfig = exports.tsConfigLoader = void 0;
var path = require("path");
var fs = require("fs");
// tslint:disable:no-require-imports
@ -16,26 +20,29 @@ var StripBom = require("strip-bom");
function tsConfigLoader(_a) {
var getEnv = _a.getEnv, cwd = _a.cwd, _b = _a.loadSync, loadSync = _b === void 0 ? loadSyncDefault : _b;
var TS_NODE_PROJECT = getEnv("TS_NODE_PROJECT");
var TS_NODE_BASEURL = getEnv("TS_NODE_BASEURL");
// tsconfig.loadSync handles if TS_NODE_PROJECT is a file or directory
var loadResult = loadSync(cwd, TS_NODE_PROJECT);
// and also overrides baseURL if TS_NODE_BASEURL is available.
var loadResult = loadSync(cwd, TS_NODE_PROJECT, TS_NODE_BASEURL);
return loadResult;
}
exports.tsConfigLoader = tsConfigLoader;
function loadSyncDefault(cwd, filename) {
function loadSyncDefault(cwd, filename, baseUrl) {
// Tsconfig.loadSync uses path.resolve. This is why we can use an absolute path as filename
var configPath = resolveConfigPath(cwd, filename);
if (!configPath) {
return {
tsConfigPath: undefined,
baseUrl: undefined,
paths: undefined
paths: undefined,
};
}
var config = loadTsconfig(configPath);
return {
tsConfigPath: configPath,
baseUrl: config && config.compilerOptions && config.compilerOptions.baseUrl,
paths: config && config.compilerOptions && config.compilerOptions.paths
baseUrl: baseUrl ||
(config && config.compilerOptions && config.compilerOptions.baseUrl),
paths: config && config.compilerOptions && config.compilerOptions.paths,
};
}
function resolveConfigPath(cwd, filename) {
@ -83,15 +90,22 @@ function loadTsconfig(configFilePath, existsSync, readFileSync) {
extendedConfig += ".json";
}
var currentDir = path.dirname(configFilePath);
var base = loadTsconfig(path.join(currentDir, extendedConfig), existsSync, readFileSync) || {};
var extendedConfigPath = path.join(currentDir, extendedConfig);
if (extendedConfig.indexOf("/") !== -1 &&
extendedConfig.indexOf(".") !== -1 &&
!existsSync(extendedConfigPath)) {
extendedConfigPath = path.join(currentDir, "node_modules", extendedConfig);
}
var base = loadTsconfig(extendedConfigPath, existsSync, readFileSync) || {};
// baseUrl should be interpreted as relative to the base tsconfig,
// but we need to update it so it is relative to the original tsconfig being loaded
if (base && base.compilerOptions && base.compilerOptions.baseUrl) {
if (base.compilerOptions && base.compilerOptions.baseUrl) {
var extendsDir = path.dirname(extendedConfig);
base.compilerOptions.baseUrl = path.join(extendsDir, base.compilerOptions.baseUrl);
}
return __assign({}, base, config, { compilerOptions: __assign({}, base.compilerOptions, config.compilerOptions) });
return __assign(__assign(__assign({}, base), config), { compilerOptions: __assign(__assign({}, base.compilerOptions), config.compilerOptions) });
}
return config;
}
exports.loadTsconfig = loadTsconfig;
//# sourceMappingURL=tsconfig-loader.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"tsconfig-loader.js","sourceRoot":"","sources":["../src/tsconfig-loader.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,2BAA6B;AAC7B,uBAAyB;AACzB,oCAAoC;AACpC,6BAAgC;AAChC,oCAAuC;AA+BvC,SAAgB,cAAc,CAAC,EAIR;QAHrB,MAAM,YAAA,EACN,GAAG,SAAA,EACH,gBAA0B,EAA1B,QAAQ,mBAAG,eAAe,KAAA;IAE1B,IAAM,eAAe,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAC;IAClD,IAAM,eAAe,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAC;IAElD,sEAAsE;IACtE,8DAA8D;IAC9D,IAAM,UAAU,GAAG,QAAQ,CAAC,GAAG,EAAE,eAAe,EAAE,eAAe,CAAC,CAAC;IACnE,OAAO,UAAU,CAAC;AACpB,CAAC;AAZD,wCAYC;AAED,SAAS,eAAe,CACtB,GAAW,EACX,QAAiB,EACjB,OAAgB;IAEhB,2FAA2F;IAE3F,IAAM,UAAU,GAAG,iBAAiB,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IAEpD,IAAI,CAAC,UAAU,EAAE;QACf,OAAO;YACL,YAAY,EAAE,SAAS;YACvB,OAAO,EAAE,SAAS;YAClB,KAAK,EAAE,SAAS;SACjB,CAAC;KACH;IACD,IAAM,MAAM,GAAG,YAAY,CAAC,UAAU,CAAC,CAAC;IAExC,OAAO;QACL,YAAY,EAAE,UAAU;QACxB,OAAO,EACL,OAAO;YACP,CAAC,MAAM,IAAI,MAAM,CAAC,eAAe,IAAI,MAAM,CAAC,eAAe,CAAC,OAAO,CAAC;QACtE,KAAK,EAAE,MAAM,IAAI,MAAM,CAAC,eAAe,IAAI,MAAM,CAAC,eAAe,CAAC,KAAK;KACxE,CAAC;AACJ,CAAC;AAED,SAAS,iBAAiB,CAAC,GAAW,EAAE,QAAiB;IACvD,IAAI,QAAQ,E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ACtC,UAAU,EACV,IAAI,CAAC,eAAe,CAAC,OAAO,CAC7B,CAAC;SACH;QAED,sCACK,IAAI,GACJ,MAAM,KACT,eAAe,wBACV,IAAI,CAAC,eAAe,GACpB,MAAM,CAAC,eAAe,KAE3B;KACH;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AA3DD,oCA2DC"}

View file

@ -1,36 +1,41 @@
{
"name": "tsconfig-paths",
"version": "3.9.0",
"version": "3.14.1",
"description": "Load node modules according to tsconfig paths, in run-time or via API.",
"main": "lib/index.js",
"types": "lib/index",
"types": "lib/index.d.ts",
"author": "Jonas Kello",
"license": "MIT",
"repository": "https://github.com/dividab/tsconfig-paths",
"files": [
"/src",
"/lib",
"register.js",
"package.json",
"CHANGELOG.md",
"LICENSE",
"README.md"
],
"devDependencies": {
"@types/chai": "^4.1.4",
"@types/minimist": "^1.2.0",
"@types/mocha": "^5.2.3",
"@types/jest": "^27.0.3",
"@types/minimist": "^1.2.2",
"@types/node": "^6.0.54",
"@types/strip-bom": "^3.0.0",
"@types/strip-json-comments": "^0.0.30",
"chai": "^4.1.2",
"codecov": "^3.1.0",
"husky": "^0.14.3",
"lint-staged": "^4.3.0",
"mocha": "^5.2.0",
"nyc": "^11.4.1",
"prettier": "1.7.4",
"husky": "^4.2.5",
"jest": "^27.3.1",
"lint-staged": "^10.2.11",
"prettier": "^2.0.5",
"rimraf": "^2.6.2",
"shelljs": "^0.7.5",
"ts-node": "^7.0.0",
"ts-jest": "^27.0.7",
"ts-node": "^10.7.0",
"tslint": "^5.8.0",
"typescript": "^2.4.1"
"typescript": "^4.5.2"
},
"dependencies": {
"@types/json5": "^0.0.29",
"json5": "^1.0.1",
"minimist": "^1.2.0",
"minimist": "^1.2.6",
"strip-bom": "^3.0.0"
},
"scripts": {
@ -39,25 +44,24 @@
"example:project": "yarn build && ts-node -r ./register.js -P ./example/project/tsconfig.json ./example/project/main.ts",
"example:api": "cd example/api && ts-node main.ts",
"example:perf": "cd example/perf && ts-node main.ts",
"test": "mocha",
"build": "rimraf lib && tsc -p src",
"build:test": "rimraf ./test/js_out && tsc -p test",
"test": "jest",
"test-coverage": "jest --coverage",
"build": "rimraf lib && tsc -p .",
"lint": "tslint './{src,tests}/**/*.ts{,x}'",
"verify": "yarn build && yarn lint && yarn coverage",
"coverage": "rimraf coverage .nyc_output && nyc yarn test",
"report-coverage": "codecov -f coverage/*.json",
"precommit": "lint-staged",
"publish:major": "yarn build && node scripts/publish.js major",
"publish:minor": "yarn build && node scripts/publish.js minor",
"publish:patch": "yarn build && node scripts/publish.js patch",
"verify": "yarn build && yarn lint && yarn test-coverage",
"preversion": "yarn verify",
"postversion": "git push --tags && yarn publish --new-version $npm_package_version && git push && echo \"Successfully released version $npm_package_version!\""
},
"lint-staged": {
"*.ts": [
"tslint",
"*.{ts,tsx}": "tslint",
"*.{ts,tsx,json,css}": [
"prettier --write",
"git add"
]
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
}
}

View file

@ -1 +1 @@
require('./').register();
require("./").register();

View file

@ -1,10 +1,9 @@
import { assert } from "chai";
import {
configLoader,
loadConfig,
ConfigLoaderFailResult,
ConfigLoaderSuccessResult
} from "../src/config-loader";
ConfigLoaderSuccessResult,
} from "../config-loader";
import { join } from "path";
describe("config-loader", (): void => {
@ -13,16 +12,19 @@ describe("config-loader", (): void => {
explicitParams: {
baseUrl: "/foo/bar",
paths: {
asd: ["asd"]
}
asd: ["asd"],
},
},
cwd: "/baz"
cwd: "/baz",
});
const successResult = result as ConfigLoaderSuccessResult;
assert.equal(successResult.resultType, "success");
assert.equal(successResult.absoluteBaseUrl, "/foo/bar");
assert.equal(successResult.paths["asd"][0], "asd");
// assert.equal(successResult.resultType, "success");
// assert.equal(successResult.absoluteBaseUrl, "/foo/bar");
// assert.equal(successResult.paths["asd"][0], "asd");
expect(successResult.resultType).toBe("success");
expect(successResult.absoluteBaseUrl).toBe("/foo/bar");
expect(successResult.paths["asd"][0]).toBe("asd");
});
it("should use explicitParams when set and add cwd when path is relative", () => {
@ -30,15 +32,17 @@ describe("config-loader", (): void => {
explicitParams: {
baseUrl: "bar/",
paths: {
asd: ["asd"]
}
asd: ["asd"],
},
},
cwd: "/baz"
cwd: "/baz",
});
const successResult = result as ConfigLoaderSuccessResult;
assert.equal(successResult.resultType, "success");
assert.equal(successResult.absoluteBaseUrl, join("/baz", "bar/"));
// assert.equal(successResult.resultType, "success");
// assert.equal(successResult.absoluteBaseUrl, join("/baz", "bar/"));
expect(successResult.resultType).toBe("success");
expect(successResult.absoluteBaseUrl).toBe(join("/baz", "bar/"));
});
it("should fallback to tsConfigLoader when explicitParams is not set", () => {
@ -49,13 +53,15 @@ describe("config-loader", (): void => {
tsConfigLoader: (_: any) => ({
tsConfigPath: "/baz/tsconfig.json",
baseUrl: "./src",
paths: {}
})
paths: {},
}),
});
const successResult = result as ConfigLoaderSuccessResult;
assert.equal(successResult.resultType, "success");
assert.equal(successResult.absoluteBaseUrl, join("/baz", "src"));
// assert.equal(successResult.resultType, "success");
// assert.equal(successResult.absoluteBaseUrl, join("/baz", "src"));
expect(successResult.resultType).toBe("success");
expect(successResult.absoluteBaseUrl).toBe(join("/baz", "src"));
});
it("should show an error message when baseUrl is missing", () => {
@ -66,13 +72,15 @@ describe("config-loader", (): void => {
tsConfigLoader: (_: any) => ({
tsConfigPath: "/baz/tsconfig.json",
baseUrl: undefined,
paths: {}
})
paths: {},
}),
});
const failResult = result as ConfigLoaderFailResult;
assert.equal(failResult.resultType, "failed");
assert.isTrue(failResult.message.indexOf("baseUrl") > -1);
// assert.equal(failResult.resultType, "failed");
// assert.isTrue(failResult.message.indexOf("baseUrl") > -1);
expect(failResult.resultType).toBe("failed");
expect(failResult.message.indexOf("baseUrl") > -1).toBeTruthy();
});
it("should presume cwd to be a tsconfig file when loadConfig is called with absolute path to tsconfig.json", () => {
@ -84,7 +92,9 @@ describe("config-loader", (): void => {
const result = loadConfig(configFile);
const successResult = result as ConfigLoaderSuccessResult;
assert.equal(successResult.resultType, "success");
assert.equal(successResult.configFileAbsolutePath, configFile);
// assert.equal(successResult.resultType, "success");
// assert.equal(successResult.configFileAbsolutePath, configFile);
expect(successResult.resultType).toBe("success");
expect(successResult.configFileAbsolutePath).toBe(configFile);
});
});

View file

@ -1,5 +1,5 @@
import { join, dirname } from "path";
import { removeExtension } from "../../src/filesystem";
import { removeExtension } from "../../filesystem";
export interface OneTest {
readonly name: string;
@ -11,32 +11,41 @@ export interface OneTest {
readonly addMatchAll?: boolean;
readonly existingFiles: ReadonlyArray<string>;
readonly requestedModule: string;
readonly extensions?: ReadonlyArray<string>;
readonly extensions: ReadonlyArray<string>;
readonly packageJson?: {};
readonly expectedPath: string | undefined;
}
const defaultExtensionsWhenRunningInTsNode = [
".js",
".json",
".node",
".ts",
".tsx",
];
export const tests: ReadonlyArray<OneTest> = [
{
name: "should locate path that matches with star and exists",
absoluteBaseUrl: "/root/",
paths: {
"lib/*": ["location/*"]
"lib/*": ["location/*"],
},
existingFiles: [join("/root", "location", "mylib", "index.ts")],
requestedModule: "lib/mylib",
expectedPath: dirname(join("/root", "location", "mylib", "index.ts"))
expectedPath: dirname(join("/root", "location", "mylib", "index.ts")),
extensions: defaultExtensionsWhenRunningInTsNode,
},
{
name: "should resolve to correct path when many are specified",
absoluteBaseUrl: "/root/",
paths: {
"lib/*": ["foo1/*", "foo2/*", "location/*", "foo3/*"]
"lib/*": ["foo1/*", "foo2/*", "location/*", "foo3/*"],
},
existingFiles: [join("/root", "location", "mylib", "index.ts")],
requestedModule: "lib/mylib",
extensions: [".ts"],
expectedPath: dirname(join("/root", "location", "mylib", "index.ts"))
expectedPath: dirname(join("/root", "location", "mylib", "index.ts")),
},
{
name:
@ -44,14 +53,15 @@ export const tests: ReadonlyArray<OneTest> = [
absoluteBaseUrl: "/root/",
paths: {
"*": ["location/*"],
"lib/*": ["location/*"]
"lib/*": ["location/*"],
},
existingFiles: [
join("/root", "location", "lib", "mylib", "index.ts"),
join("/root", "location", "mylib", "index.ts")
join("/root", "location", "mylib", "index.ts"),
],
requestedModule: "lib/mylib",
expectedPath: dirname(join("/root", "location", "mylib", "index.ts"))
expectedPath: dirname(join("/root", "location", "mylib", "index.ts")),
extensions: defaultExtensionsWhenRunningInTsNode,
},
{
name: "should locate path that matches with star and exists with extension",
@ -60,7 +70,7 @@ export const tests: ReadonlyArray<OneTest> = [
existingFiles: [join("/root", "location", "mylib.myext")],
requestedModule: "lib/mylib",
extensions: [".js", ".myext"],
expectedPath: removeExtension(join("/root", "location", "mylib.myext"))
expectedPath: removeExtension(join("/root", "location", "mylib.myext")),
},
{
name: "should resolve request with extension specified",
@ -68,17 +78,19 @@ export const tests: ReadonlyArray<OneTest> = [
paths: { "lib/*": ["location/*"] },
existingFiles: [join("/root", "location", "test.jpg")],
requestedModule: "lib/test.jpg",
expectedPath: join("/root", "location", "test.jpg")
expectedPath: join("/root", "location", "test.jpg"),
extensions: defaultExtensionsWhenRunningInTsNode,
},
{
name: "should locate path that matches without star and exists",
absoluteBaseUrl: "/root/",
paths: {
"lib/foo": ["location/foo"]
"lib/foo": ["location/foo"],
},
existingFiles: [join("/root", "location", "foo.ts")],
requestedModule: "lib/foo",
expectedPath: removeExtension(join("/root", "location", "foo.ts"))
expectedPath: removeExtension(join("/root", "location", "foo.ts")),
extensions: defaultExtensionsWhenRunningInTsNode,
},
{
name: "should resolve to parent folder when filename is in subfolder",
@ -86,7 +98,8 @@ export const tests: ReadonlyArray<OneTest> = [
paths: { "lib/*": ["location/*"] },
existingFiles: [join("/root", "location", "mylib", "index.ts")],
requestedModule: "lib/mylib",
expectedPath: dirname(join("/root", "location", "mylib", "index.ts"))
expectedPath: dirname(join("/root", "location", "mylib", "index.ts")),
extensions: defaultExtensionsWhenRunningInTsNode,
},
{
name: "should resolve from main field in package.json",
@ -95,9 +108,8 @@ export const tests: ReadonlyArray<OneTest> = [
existingFiles: [join("/root", "location", "mylib", "kalle.ts")],
packageJson: { main: "./kalle.ts" },
requestedModule: "lib/mylib",
expectedPath: removeExtension(
join("/root", "location", "mylib", "kalle.ts")
)
expectedPath: join("/root", "location", "mylib", "kalle.ts"),
extensions: defaultExtensionsWhenRunningInTsNode,
},
{
name: "should resolve from main field in package.json (js)",
@ -107,22 +119,7 @@ export const tests: ReadonlyArray<OneTest> = [
packageJson: { main: "./kalle.js" },
requestedModule: "lib/mylib.js",
extensions: [".ts", ".js"],
expectedPath: removeExtension(
join("/root", "location", "mylib.js", "kalle.js")
)
},
{
name:
"should resolve from main field in package.json and correctly remove file extension",
absoluteBaseUrl: "/root/",
paths: { "lib/*": ["location/*"] },
existingFiles: [join("/root", "location", "mylibjs", "kalle.js")],
packageJson: { main: "./kalle.js" },
extensions: [".ts", ".js"],
requestedModule: "lib/mylibjs",
expectedPath: removeExtension(
join("/root", "location", "mylibjs", "kalle.js")
)
expectedPath: join("/root", "location", "mylib.js", "kalle.js"),
},
{
name: "should resolve from list of fields by priority in package.json",
@ -132,13 +129,11 @@ export const tests: ReadonlyArray<OneTest> = [
packageJson: { main: "./main.js", browser: "./browser.js" },
existingFiles: [
join("/root", "location", "mylibjs", "main.js"), // mainFilePath
join("/root", "location", "mylibjs", "browser.js") // browserFilePath
join("/root", "location", "mylibjs", "browser.js"), // browserFilePath
],
extensions: [".ts", ".js"],
requestedModule: "lib/mylibjs",
expectedPath: removeExtension(
join("/root", "location", "mylibjs", "browser.js")
)
expectedPath: join("/root", "location", "mylibjs", "browser.js"),
},
{
name: "should ignore field mappings to missing files in package.json",
@ -149,12 +144,10 @@ export const tests: ReadonlyArray<OneTest> = [
requestedModule: "lib/mylibjs",
packageJson: {
main: "./kalle.js",
browser: "./nope.js"
browser: "./nope.js",
},
extensions: [".ts", ".js"],
expectedPath: removeExtension(
join("/root", "location", "mylibjs", "kalle.js")
)
expectedPath: join("/root", "location", "mylibjs", "kalle.js"),
},
{
name: "should ignore advanced field mappings in package.json",
@ -162,17 +155,15 @@ export const tests: ReadonlyArray<OneTest> = [
paths: { "lib/*": ["location/*"] },
existingFiles: [
join("/root", "location", "mylibjs", "kalle.js"),
join("/root", "location", "mylibjs", "browser.js")
join("/root", "location", "mylibjs", "browser.js"),
],
requestedModule: "lib/mylibjs",
packageJson: {
main: "./kalle.js",
browser: { mylibjs: "./browser.js", "./kalle.js": "./browser.js" }
browser: { mylibjs: "./browser.js", "./kalle.js": "./browser.js" },
},
extensions: [".ts", ".js"],
expectedPath: removeExtension(
join("/root", "location", "mylibjs", "kalle.js")
)
expectedPath: join("/root", "location", "mylibjs", "kalle.js"),
},
{
name: "should resolve to with the help of baseUrl when not explicitly set",
@ -180,7 +171,8 @@ export const tests: ReadonlyArray<OneTest> = [
paths: {},
existingFiles: [join("/root", "mylib", "index.ts")],
requestedModule: "mylib",
expectedPath: dirname(join("/root", "mylib", "index.ts"))
expectedPath: dirname(join("/root", "mylib", "index.ts")),
extensions: defaultExtensionsWhenRunningInTsNode,
},
{
name: "should not resolve with the help of baseUrl when asked not to",
@ -189,7 +181,8 @@ export const tests: ReadonlyArray<OneTest> = [
addMatchAll: false,
existingFiles: [join("/root", "mylib", "index.ts")],
requestedModule: "mylib",
expectedPath: undefined
expectedPath: undefined,
extensions: defaultExtensionsWhenRunningInTsNode,
},
{
name: "should not locate path that does not match",
@ -197,16 +190,30 @@ export const tests: ReadonlyArray<OneTest> = [
paths: { "lib/*": ["location/*"] },
existingFiles: [join("root", "location", "mylib")],
requestedModule: "mylib",
expectedPath: undefined
expectedPath: undefined,
extensions: defaultExtensionsWhenRunningInTsNode,
},
{
name: "should not resolve typings file (index.d.ts)",
absoluteBaseUrl: "/root/",
paths: {
"lib/*": ["location/*"]
"lib/*": ["location/*"],
},
existingFiles: [join("/root", "location", "mylib", "index.d.ts")],
requestedModule: "lib/mylib",
expectedPath: undefined
}
expectedPath: undefined,
extensions: defaultExtensionsWhenRunningInTsNode,
},
{
name: "should resolve main file with cjs file extension",
absoluteBaseUrl: "/root/",
paths: {},
existingFiles: [join("/root", "mylib", "index.cjs")],
packageJson: {
main: "./index.cjs",
},
requestedModule: "mylib",
expectedPath: join("/root", "mylib", "index.cjs"),
extensions: defaultExtensionsWhenRunningInTsNode,
},
];

View file

@ -0,0 +1,65 @@
import * as Filesystem from "../filesystem";
import * as path from "path";
describe("filesystem", () => {
const fileThatExists = path.join(__dirname, "../../package.json");
const fileThatNotExists = path.join(__dirname, "../../package2.json");
it("should find file that exists, sync", () => {
const result = Filesystem.fileExistsSync(fileThatExists);
// assert.equal(result, true);
expect(result).toBe(true);
});
it("should not find file that not exists, sync", () => {
const result = Filesystem.fileExistsSync(fileThatNotExists);
// assert.equal(result, false);
expect(result).toBe(false);
});
it("should find file that exists, async", (done) => {
Filesystem.fileExistsAsync(fileThatExists, (_err, result) => {
try {
// assert.equal(result, true);
expect(result).toBe(true);
done();
} catch (error) {
done(error);
}
});
});
it("should not find file that not exists, async", (done) => {
Filesystem.fileExistsAsync(fileThatNotExists, (_err, result) => {
try {
// assert.equal(result, false);
expect(result).toBe(false);
done();
} catch (error) {
done(error);
}
});
});
it("should load json, sync", () => {
const result = Filesystem.readJsonFromDiskSync(fileThatExists);
// assert.isOk(result);
expect(result);
// assert.equal(result.main, "lib/index.js");
expect(result.main).toBe("lib/index.js");
});
it("should load json, async", (done) => {
Filesystem.readJsonFromDiskAsync(fileThatExists, (_err, result) => {
try {
// assert.isOk(result); // Asserts that object is truthy.
expect(result).toBeTruthy();
// assert.equal(result.main, "lib/index.js");
expect(result.main).toBe("lib/index.js");
done();
} catch (error) {
done(error);
}
});
});
});

View file

@ -0,0 +1,70 @@
import { getAbsoluteMappingEntries } from "../mapping-entry";
import { join } from "path";
describe("mapping-entry", () => {
it("should change to absolute paths and sort in longest prefix order", () => {
const result = getAbsoluteMappingEntries(
"/absolute/base/url",
{
"*": ["/foo1", "/foo2"],
"longest/pre/fix/*": ["/foo2/bar"],
"pre/fix/*": ["/foo3"],
},
true
);
// assert.deepEqual(result, [
// {
// pattern: "longest/pre/fix/*",
// paths: [join("/absolute", "base", "url", "foo2", "bar")],
// },
// {
// pattern: "pre/fix/*",
// paths: [join("/absolute", "base", "url", "foo3")],
// },
// {
// pattern: "*",
// paths: [
// join("/absolute", "base", "url", "foo1"),
// join("/absolute", "base", "url", "foo2"),
// ],
// },
// ]);
expect(result).toEqual([
{
pattern: "longest/pre/fix/*",
paths: [join("/absolute", "base", "url", "foo2", "bar")],
},
{
pattern: "pre/fix/*",
paths: [join("/absolute", "base", "url", "foo3")],
},
{
pattern: "*",
paths: [
join("/absolute", "base", "url", "foo1"),
join("/absolute", "base", "url", "foo2"),
],
},
]);
});
it("should should add a match-all pattern when requested", () => {
let result = getAbsoluteMappingEntries("/absolute/base/url", {}, true);
// assert.deepEqual(result, [
// {
// pattern: "*",
// paths: [join("/absolute", "base", "url", "*")],
// },
// ]);
expect(result).toEqual([
{
pattern: "*",
paths: [join("/absolute", "base", "url", "*")],
},
]);
result = getAbsoluteMappingEntries("/absolute/base/url", {}, false);
// assert.deepEqual(result, []);
expect(result).toEqual([]);
});
});

View file

@ -1,10 +1,9 @@
import { assert } from "chai";
import { createMatchPathAsync } from "../src/match-path-async";
import { createMatchPathAsync } from "../match-path-async";
import * as Tests from "./data/match-path-data";
describe("match-path-async", () => {
Tests.tests.forEach(t =>
it(t.name, done => {
Tests.tests.forEach((t) =>
it(t.name, (done) => {
const matchPath = createMatchPathAsync(
t.absoluteBaseUrl,
t.paths,
@ -18,7 +17,8 @@ describe("match-path-async", () => {
callback(undefined, t.existingFiles.indexOf(path) !== -1),
t.extensions,
(_err, result) => {
assert.equal(result, t.expectedPath);
// assert.equal(result, t.expectedPath);
expect(result).toBe(t.expectedPath);
done();
}
);

View file

@ -1,9 +1,8 @@
import { assert } from "chai";
import { createMatchPath } from "../src/match-path-sync";
import { createMatchPath } from "../match-path-sync";
import * as Tests from "./data/match-path-data";
describe("match-path-sync", () => {
Tests.tests.forEach(t =>
Tests.tests.forEach((t) =>
it(t.name, () => {
const matchPath = createMatchPath(
t.absoluteBaseUrl,
@ -14,10 +13,11 @@ describe("match-path-sync", () => {
const result = matchPath(
t.requestedModule,
(_: string) => t.packageJson,
(name: string) => t.existingFiles.indexOf(name) !== -1, // fileExists
(name: string) => t.existingFiles.indexOf(name) !== -1,
t.extensions
);
assert.equal(result, t.expectedPath);
// assert.equal(result, t.expectedPath);
expect(result).toBe(t.expectedPath);
})
);
});

View file

@ -0,0 +1,193 @@
import { getPathsToTry } from "../try-path";
import { join } from "path";
describe("mapping-entry", () => {
const abosolutePathMappings = [
{
pattern: "longest/pre/fix/*",
paths: [join("/absolute", "base", "url", "foo2", "bar")],
},
{ pattern: "pre/fix/*", paths: [join("/absolute", "base", "url", "foo3")] },
{ pattern: "*", paths: [join("/absolute", "base", "url", "foo1")] },
];
const abosolutePathMappingsStarstWithSlash = [
{
pattern: "/opt/*",
paths: [join("/absolute", "src", "aws-layer")],
},
{
pattern: "*",
paths: [join("/absolute", "src")],
},
];
it("should return no paths for relative requested module", () => {
const result = getPathsToTry(
[".ts", "tsx"],
abosolutePathMappings,
"./requested-module"
);
// assert.deepEqual(result, undefined);
expect(result).toBeUndefined();
});
it("should return no paths if no pattern match the requested module", () => {
const result = getPathsToTry(
[".ts", "tsx"],
[
{
pattern: "longest/pre/fix/*",
paths: [join("/absolute", "base", "url", "foo2", "bar")],
},
{
pattern: "pre/fix/*",
paths: [join("/absolute", "base", "url", "foo3")],
},
],
"requested-module"
);
expect(result).toBeUndefined();
});
it("should get all paths that matches requested module", () => {
const result = getPathsToTry(
[".ts", ".tsx"],
abosolutePathMappings,
"longest/pre/fix/requested-module"
);
// assert.deepEqual(result, [
// // "longest/pre/fix/*"
// { type: "file", path: join("/absolute", "base", "url", "foo2", "bar") },
// {
// type: "extension",
// path: join("/absolute", "base", "url", "foo2", "bar.ts"),
// },
// {
// type: "extension",
// path: join("/absolute", "base", "url", "foo2", "bar.tsx"),
// },
// {
// type: "package",
// path: join("/absolute", "base", "url", "foo2", "bar", "package.json"),
// },
// {
// type: "index",
// path: join("/absolute", "base", "url", "foo2", "bar", "index.ts"),
// },
// {
// type: "index",
// path: join("/absolute", "base", "url", "foo2", "bar", "index.tsx"),
// },
// // "*"
// { type: "file", path: join("/absolute", "base", "url", "foo1") },
// { type: "extension", path: join("/absolute", "base", "url", "foo1.ts") },
// { type: "extension", path: join("/absolute", "base", "url", "foo1.tsx") },
// {
// type: "package",
// path: join("/absolute", "base", "url", "foo1", "package.json"),
// },
// {
// type: "index",
// path: join("/absolute", "base", "url", "foo1", "index.ts"),
// },
// {
// type: "index",
// path: join("/absolute", "base", "url", "foo1", "index.tsx"),
// },
// ]);
expect(result).toEqual([
// "longest/pre/fix/*"
{ type: "file", path: join("/absolute", "base", "url", "foo2", "bar") },
{
type: "extension",
path: join("/absolute", "base", "url", "foo2", "bar.ts"),
},
{
type: "extension",
path: join("/absolute", "base", "url", "foo2", "bar.tsx"),
},
{
type: "package",
path: join("/absolute", "base", "url", "foo2", "bar", "package.json"),
},
{
type: "index",
path: join("/absolute", "base", "url", "foo2", "bar", "index.ts"),
},
{
type: "index",
path: join("/absolute", "base", "url", "foo2", "bar", "index.tsx"),
},
// "*"
{ type: "file", path: join("/absolute", "base", "url", "foo1") },
{ type: "extension", path: join("/absolute", "base", "url", "foo1.ts") },
{ type: "extension", path: join("/absolute", "base", "url", "foo1.tsx") },
{
type: "package",
path: join("/absolute", "base", "url", "foo1", "package.json"),
},
{
type: "index",
path: join("/absolute", "base", "url", "foo1", "index.ts"),
},
{
type: "index",
path: join("/absolute", "base", "url", "foo1", "index.tsx"),
},
]);
});
it("should resolve paths starting with a slash", () => {
const result = getPathsToTry(
[".ts"],
abosolutePathMappingsStarstWithSlash,
"/opt/utils"
);
expect(result).toEqual([
// "opt/*"
{
path: join("/absolute", "src", "aws-layer"),
type: "file",
},
{
path: join("/absolute", "src", "aws-layer.ts"),
type: "extension",
},
{
path: join("/absolute", "src", "aws-layer", "package.json"),
type: "package",
},
{
path: join("/absolute", "src", "aws-layer", "index.ts"),
type: "index",
},
// "*"
{
path: join("/absolute", "src"),
type: "file",
},
{
path: join("/absolute", "src.ts"),
type: "extension",
},
{
path: join("/absolute", "src", "package.json"),
type: "package",
},
{
path: join("/absolute", "src", "index.ts"),
type: "index",
},
]);
});
});
// describe("match-star", () => {
// it("should match star in last position", () => {
// const result = matchStar("lib/*", "lib/mylib");
// assert.equal(result, "mylib");
// });
// it("should match star in first position", () => {
// const result = matchStar("*/lib", "mylib/lib");
// assert.equal(result, "mylib");
// });
// });

View file

@ -1,9 +1,8 @@
import { assert } from "chai";
import {
loadTsconfig,
tsConfigLoader,
walkForTsConfig
} from "../src/tsconfig-loader";
walkForTsConfig,
} from "../tsconfig-loader";
import { join } from "path";
describe("tsconfig-loader", () => {
@ -15,12 +14,13 @@ describe("tsconfig-loader", () => {
return {
tsConfigPath: `${cwd}/tsconfig.json`,
baseUrl: "./",
paths: {}
paths: {},
};
}
},
});
assert.equal(result.tsConfigPath, "/foo/bar/tsconfig.json");
// assert.equal(result.tsConfigPath, "/foo/bar/tsconfig.json");
expect(result.tsConfigPath).toBe("/foo/bar/tsconfig.json");
});
it("should return loaderResult.tsConfigPath as undefined when not found", () => {
@ -31,12 +31,13 @@ describe("tsconfig-loader", () => {
return {
tsConfigPath: undefined,
baseUrl: "./",
paths: {}
paths: {},
};
}
},
});
assert.isUndefined(result.tsConfigPath);
// assert.isUndefined(result.tsConfigPath);
expect(result.tsConfigPath).toBeUndefined();
});
it("should use TS_NODE_PROJECT env if exists", () => {
@ -49,19 +50,57 @@ describe("tsconfig-loader", () => {
return {
tsConfigPath: "/foo/baz/tsconfig.json",
baseUrl: "./",
paths: {}
paths: {},
};
}
return {
tsConfigPath: undefined,
baseUrl: "./",
paths: {}
paths: {},
};
}
},
});
assert.equal(result.tsConfigPath, "/foo/baz/tsconfig.json");
// assert.equal(result.tsConfigPath, "/foo/baz/tsconfig.json");
expect(result.tsConfigPath).toBe("/foo/baz/tsconfig.json");
});
it("should use TS_NODE_BASEURL env if exists", () => {
const result = tsConfigLoader({
cwd: "/foo/bar",
getEnv: (key: string) =>
key === "TS_NODE_BASEURL" ? "SOME_BASEURL" : undefined,
loadSync: (_0: string, _1: string, baseUrl: string) => {
return {
tsConfigPath: undefined,
baseUrl,
paths: {},
};
},
});
// assert.equal(result.baseUrl, "SOME_BASEURL");
expect(result.baseUrl).toBe("SOME_BASEURL");
});
it("should not use TS_NODE_BASEURL env if it does not exist", () => {
const result = tsConfigLoader({
cwd: "/foo/bar",
getEnv: (_: string) => {
return undefined;
},
loadSync: (_0: string, _1: string, baseUrl: string) => {
return {
tsConfigPath: undefined,
baseUrl,
paths: {},
};
},
});
// assert.equal(result.baseUrl, undefined);
expect(result.baseUrl).toBeUndefined();
});
});
@ -70,23 +109,26 @@ describe("walkForTsConfig", () => {
const pathToTsconfig = join("/root", "dir1", "tsconfig.json");
const res = walkForTsConfig(
join("/root", "dir1"),
path => path === pathToTsconfig
(path) => path === pathToTsconfig
);
assert.equal(res, pathToTsconfig);
// assert.equal(res, pathToTsconfig);
expect(res).toBe(pathToTsconfig);
});
it("should find tsconfig in parent directory", () => {
const pathToTsconfig = join("/root", "tsconfig.json");
const res = walkForTsConfig(
join("/root", "dir1"),
path => path === pathToTsconfig
(path) => path === pathToTsconfig
);
assert.equal(res, pathToTsconfig);
// assert.equal(res, pathToTsconfig);
expect(res).toBe(pathToTsconfig);
});
it("should return undefined when reaching the top", () => {
const res = walkForTsConfig(join("/root", "dir1", "kalle"), () => false);
assert.equal(res, undefined);
// assert.equal(res, undefined);
expect(res).toBeUndefined();
});
});
@ -95,59 +137,62 @@ describe("loadConfig", () => {
const config = { compilerOptions: { baseUrl: "hej" } };
const res = loadTsconfig(
"/root/dir1/tsconfig.json",
path => path === "/root/dir1/tsconfig.json",
_ => JSON.stringify(config)
(path) => path === "/root/dir1/tsconfig.json",
(_) => JSON.stringify(config)
);
assert.deepEqual(res, config);
// assert.deepEqual(res, config);
expect(res).toStrictEqual(config);
});
it("It should load a config with comments", () => {
const config = { compilerOptions: { baseUrl: "hej" } };
const res = loadTsconfig(
"/root/dir1/tsconfig.json",
path => path === "/root/dir1/tsconfig.json",
_ => `{
(path) => path === "/root/dir1/tsconfig.json",
(_) => `{
// my comment
"compilerOptions": {
"baseUrl": "hej"
}
}`
);
assert.deepEqual(res, config);
// assert.deepEqual(res, config);
expect(res).toStrictEqual(config);
});
it("It should load a config with trailing commas", () => {
const config = { compilerOptions: { baseUrl: "hej" } };
const res = loadTsconfig(
"/root/dir1/tsconfig.json",
path => path === "/root/dir1/tsconfig.json",
_ => `{
(path) => path === "/root/dir1/tsconfig.json",
(_) => `{
"compilerOptions": {
"baseUrl": "hej",
},
}`
);
assert.deepEqual(res, config);
// assert.deepEqual(res, config);
expect(res).toStrictEqual(config);
});
it("It should load a config with extends and overwrite all options", () => {
const firstConfig = {
extends: "../base-config.json",
compilerOptions: { baseUrl: "kalle", paths: { foo: ["bar2"] } }
compilerOptions: { baseUrl: "kalle", paths: { foo: ["bar2"] } },
};
const firstConfigPath = join("/root", "dir1", "tsconfig.json");
const baseConfig = {
compilerOptions: {
baseUrl: "olle",
paths: { foo: ["bar1"] },
strict: true
}
strict: true,
},
};
const baseConfigPath = join("/root", "base-config.json");
const res = loadTsconfig(
join("/root", "dir1", "tsconfig.json"),
path => path === firstConfigPath || path === baseConfigPath,
path => {
(path) => path === firstConfigPath || path === baseConfigPath,
(path) => {
if (path === firstConfigPath) {
return JSON.stringify(firstConfig);
}
@ -158,13 +203,73 @@ describe("loadConfig", () => {
}
);
assert.deepEqual(res, {
// assert.deepEqual(res, {
// extends: "../base-config.json",
// compilerOptions: {
// baseUrl: "kalle",
// paths: { foo: ["bar2"] },
// strict: true,
// },
// });
expect(res).toEqual({
extends: "../base-config.json",
compilerOptions: {
baseUrl: "kalle",
paths: { foo: ["bar2"] },
strict: true
strict: true,
},
});
});
it("It should load a config with extends from node_modules and overwrite all options", () => {
const firstConfig = {
extends: "my-package/base-config.json",
compilerOptions: { baseUrl: "kalle", paths: { foo: ["bar2"] } },
};
const firstConfigPath = join("/root", "dir1", "tsconfig.json");
const baseConfig = {
compilerOptions: {
baseUrl: "olle",
paths: { foo: ["bar1"] },
strict: true,
},
};
const baseConfigPath = join(
"/root",
"dir1",
"node_modules",
"my-package",
"base-config.json"
);
const res = loadTsconfig(
join("/root", "dir1", "tsconfig.json"),
(path) => path === firstConfigPath || path === baseConfigPath,
(path) => {
if (path === firstConfigPath) {
return JSON.stringify(firstConfig);
}
if (path === baseConfigPath) {
return JSON.stringify(baseConfig);
}
return "";
}
);
// assert.deepEqual(res, {
// extends: "my-package/base-config.json",
// compilerOptions: {
// baseUrl: "kalle",
// paths: { foo: ["bar2"] },
// strict: true,
// },
// });
expect(res).toEqual({
extends: "my-package/base-config.json",
compilerOptions: {
baseUrl: "kalle",
paths: { foo: ["bar2"] },
strict: true,
},
});
});
@ -177,11 +282,11 @@ describe("loadConfig", () => {
const thirdConfigPath = join("/root", "dir1", "dir2", "third-config.json");
const res = loadTsconfig(
join("/root", "dir1", "dir2", "third-config.json"),
path =>
(path) =>
path === firstConfigPath ||
path === secondConfigPath ||
path === thirdConfigPath,
path => {
(path) => {
if (path === firstConfigPath) {
return JSON.stringify(firstConfig);
}
@ -195,9 +300,13 @@ describe("loadConfig", () => {
}
);
assert.deepEqual(res, {
// assert.deepEqual(res, {
// extends: "../second-config.json",
// compilerOptions: { baseUrl: join("..", "..") },
// });
expect(res).toEqual({
extends: "../second-config.json",
compilerOptions: { baseUrl: join("..", "..") }
compilerOptions: { baseUrl: join("..", "..") },
});
});
});

97
node_modules/tsconfig-paths/src/config-loader.ts generated vendored Normal file
View file

@ -0,0 +1,97 @@
import * as TsConfigLoader2 from "./tsconfig-loader";
import * as path from "path";
import { options } from "./options";
export interface ExplicitParams {
baseUrl: string;
paths: { [key: string]: Array<string> };
mainFields?: Array<string>;
addMatchAll?: boolean;
}
export type TsConfigLoader = (
params: TsConfigLoader2.TsConfigLoaderParams
) => TsConfigLoader2.TsConfigLoaderResult;
export interface ConfigLoaderParams {
cwd: string;
explicitParams?: ExplicitParams;
tsConfigLoader?: TsConfigLoader;
}
export interface ConfigLoaderSuccessResult {
resultType: "success";
configFileAbsolutePath: string;
baseUrl: string;
absoluteBaseUrl: string;
paths: { [key: string]: Array<string> };
mainFields?: Array<string>;
addMatchAll?: boolean;
}
export interface ConfigLoaderFailResult {
resultType: "failed";
message: string;
}
export type ConfigLoaderResult =
| ConfigLoaderSuccessResult
| ConfigLoaderFailResult;
export function loadConfig(cwd: string = options.cwd): ConfigLoaderResult {
return configLoader({ cwd: cwd });
}
export function configLoader({
cwd,
explicitParams,
tsConfigLoader = TsConfigLoader2.tsConfigLoader,
}: ConfigLoaderParams): ConfigLoaderResult {
if (explicitParams) {
// tslint:disable-next-line:no-shadowed-variable
const absoluteBaseUrl = path.isAbsolute(explicitParams.baseUrl)
? explicitParams.baseUrl
: path.join(cwd, explicitParams.baseUrl);
return {
resultType: "success",
configFileAbsolutePath: "",
baseUrl: explicitParams.baseUrl,
absoluteBaseUrl,
paths: explicitParams.paths,
mainFields: explicitParams.mainFields,
addMatchAll: explicitParams.addMatchAll,
};
}
// Load tsconfig and create path matching function
const loadResult = tsConfigLoader({
cwd,
getEnv: (key: string) => process.env[key],
});
if (!loadResult.tsConfigPath) {
return {
resultType: "failed",
message: "Couldn't find tsconfig.json",
};
}
if (!loadResult.baseUrl) {
return {
resultType: "failed",
message: "Missing baseUrl in compilerOptions",
};
}
const tsConfigDir = path.dirname(loadResult.tsConfigPath);
const absoluteBaseUrl = path.join(tsConfigDir, loadResult.baseUrl);
return {
resultType: "success",
configFileAbsolutePath: loadResult.tsConfigPath,
baseUrl: loadResult.baseUrl,
absoluteBaseUrl,
paths: loadResult.paths || {},
};
}

87
node_modules/tsconfig-paths/src/filesystem.ts generated vendored Normal file
View file

@ -0,0 +1,87 @@
import * as fs from "fs";
/**
* Typing for the fields of package.json we care about
*/
export interface PackageJson {
[key: string]: string;
}
/**
* A function that json from a file
*/
export interface ReadJsonSync {
// tslint:disable-next-line:no-any
(packageJsonPath: string): any | undefined;
}
export interface FileExistsSync {
(name: string): boolean;
}
export interface FileExistsAsync {
(path: string, callback: (err?: Error, exists?: boolean) => void): void;
}
export interface ReadJsonAsyncCallback {
// tslint:disable-next-line:no-any
(err?: Error, content?: any): void;
}
export interface ReadJsonAsync {
(path: string, callback: ReadJsonAsyncCallback): void;
}
export function fileExistsSync(path: string): boolean {
try {
const stats = fs.statSync(path);
return stats.isFile();
} catch (err) {
// If error, assume file did not exist
return false;
}
}
/**
* Reads package.json from disk
* @param file Path to package.json
*/
// tslint:disable-next-line:no-any
export function readJsonFromDiskSync(packageJsonPath: string): any | undefined {
if (!fs.existsSync(packageJsonPath)) {
return undefined;
}
return require(packageJsonPath);
}
export function readJsonFromDiskAsync(
path: string,
// tslint:disable-next-line:no-any
callback: (err?: Error, content?: any) => void
): void {
fs.readFile(path, "utf8", (err, result) => {
// If error, assume file did not exist
if (err || !result) {
return callback();
}
const json = JSON.parse(result);
return callback(undefined, json);
});
}
export function fileExistsAsync(
path2: string,
callback2: (err?: Error, exists?: boolean) => void
): void {
fs.stat(path2, (err: Error, stats: fs.Stats) => {
if (err) {
// If error assume file does not exist
return callback2(undefined, false);
}
callback2(undefined, stats ? stats.isFile() : false);
});
}
export function removeExtension(path: string): string {
return path.substring(0, path.lastIndexOf(".")) || path;
}

24
node_modules/tsconfig-paths/src/index.ts generated vendored Normal file
View file

@ -0,0 +1,24 @@
// register is used from register.js in root dir
export {
createMatchPath,
matchFromAbsolutePaths,
MatchPath,
} from "./match-path-sync";
export {
createMatchPathAsync,
matchFromAbsolutePathsAsync,
MatchPathAsync,
} from "./match-path-async";
export { register } from "./register";
export {
loadConfig,
ConfigLoaderResult,
ConfigLoaderSuccessResult,
ConfigLoaderFailResult,
} from "./config-loader";
export {
ReadJsonSync,
ReadJsonAsync,
FileExistsSync,
FileExistsAsync,
} from "./filesystem";

64
node_modules/tsconfig-paths/src/mapping-entry.ts generated vendored Normal file
View file

@ -0,0 +1,64 @@
import * as path from "path";
export interface MappingEntry {
readonly pattern: string;
readonly paths: ReadonlyArray<string>;
}
export interface Paths {
readonly [key: string]: ReadonlyArray<string>;
}
/**
* Converts an absolute baseUrl and paths to an array of absolute mapping entries.
* The array is sorted by longest prefix.
* Having an array with entries allows us to keep a sorting order rather than
* sort by keys each time we use the mappings.
* @param absoluteBaseUrl
* @param paths
* @param addMatchAll
*/
export function getAbsoluteMappingEntries(
absoluteBaseUrl: string,
paths: Paths,
addMatchAll: boolean
): ReadonlyArray<MappingEntry> {
// Resolve all paths to absolute form once here, and sort them by
// longest prefix once here, this saves time on each request later.
// We need to put them in an array to preserve the sorting order.
const sortedKeys = sortByLongestPrefix(Object.keys(paths));
const absolutePaths: Array<MappingEntry> = [];
for (const key of sortedKeys) {
absolutePaths.push({
pattern: key,
paths: paths[key].map((pathToResolve) =>
path.join(absoluteBaseUrl, pathToResolve)
),
});
}
// If there is no match-all path specified in the paths section of tsconfig, then try to match
// all paths relative to baseUrl, this is how typescript works.
if (!paths["*"] && addMatchAll) {
absolutePaths.push({
pattern: "*",
paths: [`${absoluteBaseUrl.replace(/\/$/, "")}/*`],
});
}
return absolutePaths;
}
/**
* Sort path patterns.
* If a module name can be matched with multiple patterns then pattern with the longest prefix will be picked.
*/
function sortByLongestPrefix(arr: Array<string>): Array<string> {
return arr
.concat()
.sort((a: string, b: string) => getPrefixLength(b) - getPrefixLength(a));
}
function getPrefixLength(pattern: string): number {
const prefixLength = pattern.indexOf("*");
return pattern.substr(0, prefixLength).length;
}

218
node_modules/tsconfig-paths/src/match-path-async.ts generated vendored Normal file
View file

@ -0,0 +1,218 @@
import * as path from "path";
import * as TryPath from "./try-path";
import * as MappingEntry from "./mapping-entry";
import * as Filesystem from "./filesystem";
/**
* Function that can match a path async
*/
export interface MatchPathAsync {
(
requestedModule: string,
readJson: Filesystem.ReadJsonAsync | undefined,
fileExists: Filesystem.FileExistsAsync | undefined,
extensions: ReadonlyArray<string> | undefined,
callback: MatchPathAsyncCallback
): void;
}
export interface MatchPathAsyncCallback {
(err?: Error, path?: string): void;
}
/**
* See the sync version for docs.
*/
export function createMatchPathAsync(
absoluteBaseUrl: string,
paths: { [key: string]: Array<string> },
mainFields: string[] = ["main"],
addMatchAll: boolean = true
): MatchPathAsync {
const absolutePaths = MappingEntry.getAbsoluteMappingEntries(
absoluteBaseUrl,
paths,
addMatchAll
);
return (
requestedModule: string,
readJson: Filesystem.ReadJsonAsync | undefined,
fileExists: Filesystem.FileExistsAsync | undefined,
extensions: ReadonlyArray<string> | undefined,
callback: MatchPathAsyncCallback
) =>
matchFromAbsolutePathsAsync(
absolutePaths,
requestedModule,
readJson,
fileExists,
extensions,
callback,
mainFields
);
}
/**
* See the sync version for docs.
*/
export function matchFromAbsolutePathsAsync(
absolutePathMappings: ReadonlyArray<MappingEntry.MappingEntry>,
requestedModule: string,
readJson: Filesystem.ReadJsonAsync = Filesystem.readJsonFromDiskAsync,
fileExists: Filesystem.FileExistsAsync = Filesystem.fileExistsAsync,
extensions: ReadonlyArray<string> = Object.keys(require.extensions),
callback: MatchPathAsyncCallback,
mainFields: string[] = ["main"]
): void {
const tryPaths = TryPath.getPathsToTry(
extensions,
absolutePathMappings,
requestedModule
);
if (!tryPaths) {
return callback();
}
findFirstExistingPath(
tryPaths,
readJson,
fileExists,
callback,
0,
mainFields
);
}
function findFirstExistingMainFieldMappedFile(
packageJson: Filesystem.PackageJson,
mainFields: string[],
packageJsonPath: string,
fileExistsAsync: Filesystem.FileExistsAsync,
doneCallback: (err?: Error, filepath?: string) => void,
index: number = 0
): void {
if (index >= mainFields.length) {
return doneCallback(undefined, undefined);
}
const tryNext = () =>
findFirstExistingMainFieldMappedFile(
packageJson,
mainFields,
packageJsonPath,
fileExistsAsync,
doneCallback,
index + 1
);
const mainFieldMapping = packageJson[mainFields[index]];
if (typeof mainFieldMapping !== "string") {
// Skip mappings that are not pointers to replacement files
return tryNext();
}
const mappedFilePath = path.join(
path.dirname(packageJsonPath),
mainFieldMapping
);
fileExistsAsync(mappedFilePath, (err?: Error, exists?: boolean) => {
if (err) {
return doneCallback(err);
}
if (exists) {
return doneCallback(undefined, mappedFilePath);
}
return tryNext();
});
}
// Recursive loop to probe for physical files
function findFirstExistingPath(
tryPaths: ReadonlyArray<TryPath.TryPath>,
readJson: Filesystem.ReadJsonAsync,
fileExists: Filesystem.FileExistsAsync,
doneCallback: MatchPathAsyncCallback,
index: number = 0,
mainFields: string[] = ["main"]
): void {
const tryPath = tryPaths[index];
if (
tryPath.type === "file" ||
tryPath.type === "extension" ||
tryPath.type === "index"
) {
fileExists(tryPath.path, (err: Error, exists: boolean) => {
if (err) {
return doneCallback(err);
}
if (exists) {
return doneCallback(undefined, TryPath.getStrippedPath(tryPath));
}
if (index === tryPaths.length - 1) {
return doneCallback();
}
// Continue with the next path
return findFirstExistingPath(
tryPaths,
readJson,
fileExists,
doneCallback,
index + 1,
mainFields
);
});
} else if (tryPath.type === "package") {
readJson(tryPath.path, (err, packageJson) => {
if (err) {
return doneCallback(err);
}
if (packageJson) {
return findFirstExistingMainFieldMappedFile(
packageJson,
mainFields,
tryPath.path,
fileExists,
(mainFieldErr?: Error, mainFieldMappedFile?: string) => {
if (mainFieldErr) {
return doneCallback(mainFieldErr);
}
if (mainFieldMappedFile) {
return doneCallback(undefined, mainFieldMappedFile);
}
// No field in package json was a valid option. Continue with the next path.
return findFirstExistingPath(
tryPaths,
readJson,
fileExists,
doneCallback,
index + 1,
mainFields
);
}
);
}
// This is async code, we need to return unconditionally, otherwise the code still falls
// through and keeps recursing. While this might work in general, libraries that use neo-async
// like Webpack will actually not allow you to call the same callback twice.
//
// An example of where this caused issues:
// https://github.com/dividab/tsconfig-paths-webpack-plugin/issues/11
//
// Continue with the next path
return findFirstExistingPath(
tryPaths,
readJson,
fileExists,
doneCallback,
index + 1,
mainFields
);
});
} else {
TryPath.exhaustiveTypeException(tryPath.type);
}
}

141
node_modules/tsconfig-paths/src/match-path-sync.ts generated vendored Normal file
View file

@ -0,0 +1,141 @@
import * as path from "path";
import * as Filesystem from "./filesystem";
import * as MappingEntry from "./mapping-entry";
import * as TryPath from "./try-path";
/**
* Function that can match a path
*/
export interface MatchPath {
(
requestedModule: string,
readJson?: Filesystem.ReadJsonSync,
fileExists?: (name: string) => boolean,
extensions?: ReadonlyArray<string>
): string | undefined;
}
/**
* Creates a function that can resolve paths according to tsconfig paths property.
* @param absoluteBaseUrl Absolute version of baseUrl as specified in tsconfig.
* @param paths The paths as specified in tsconfig.
* @param mainFields A list of package.json field names to try when resolving module files.
* @param addMatchAll Add a match-all "*" rule if none is present
* @returns a function that can resolve paths.
*/
export function createMatchPath(
absoluteBaseUrl: string,
paths: { [key: string]: Array<string> },
mainFields: string[] = ["main"],
addMatchAll: boolean = true
): MatchPath {
const absolutePaths = MappingEntry.getAbsoluteMappingEntries(
absoluteBaseUrl,
paths,
addMatchAll
);
return (
requestedModule: string,
readJson?: Filesystem.ReadJsonSync,
fileExists?: Filesystem.FileExistsSync,
extensions?: Array<string>
) =>
matchFromAbsolutePaths(
absolutePaths,
requestedModule,
readJson,
fileExists,
extensions,
mainFields
);
}
/**
* Finds a path from tsconfig that matches a module load request.
* @param absolutePathMappings The paths to try as specified in tsconfig but resolved to absolute form.
* @param requestedModule The required module name.
* @param readJson Function that can read json from a path (useful for testing).
* @param fileExists Function that checks for existence of a file at a path (useful for testing).
* @param extensions File extensions to probe for (useful for testing).
* @param mainFields A list of package.json field names to try when resolving module files.
* @returns the found path, or undefined if no path was found.
*/
export function matchFromAbsolutePaths(
absolutePathMappings: ReadonlyArray<MappingEntry.MappingEntry>,
requestedModule: string,
readJson: Filesystem.ReadJsonSync = Filesystem.readJsonFromDiskSync,
fileExists: Filesystem.FileExistsSync = Filesystem.fileExistsSync,
extensions: Array<string> = Object.keys(require.extensions),
mainFields: string[] = ["main"]
): string | undefined {
const tryPaths = TryPath.getPathsToTry(
extensions,
absolutePathMappings,
requestedModule
);
if (!tryPaths) {
return undefined;
}
return findFirstExistingPath(tryPaths, readJson, fileExists, mainFields);
}
function findFirstExistingMainFieldMappedFile(
packageJson: Filesystem.PackageJson,
mainFields: string[],
packageJsonPath: string,
fileExists: Filesystem.FileExistsSync
): string | undefined {
for (let index = 0; index < mainFields.length; index++) {
const mainFieldName = mainFields[index];
const candidateMapping = packageJson[mainFieldName];
if (candidateMapping && typeof candidateMapping === "string") {
const candidateFilePath = path.join(
path.dirname(packageJsonPath),
candidateMapping
);
if (fileExists(candidateFilePath)) {
return candidateFilePath;
}
}
}
return undefined;
}
function findFirstExistingPath(
tryPaths: ReadonlyArray<TryPath.TryPath>,
readJson: Filesystem.ReadJsonSync = Filesystem.readJsonFromDiskSync,
fileExists: Filesystem.FileExistsSync,
mainFields: string[] = ["main"]
): string | undefined {
for (const tryPath of tryPaths) {
if (
tryPath.type === "file" ||
tryPath.type === "extension" ||
tryPath.type === "index"
) {
if (fileExists(tryPath.path)) {
return TryPath.getStrippedPath(tryPath);
}
} else if (tryPath.type === "package") {
const packageJson: Filesystem.PackageJson = readJson(tryPath.path);
if (packageJson) {
const mainFieldMappedFile = findFirstExistingMainFieldMappedFile(
packageJson,
mainFields,
tryPath.path,
fileExists
);
if (mainFieldMappedFile) {
return mainFieldMappedFile;
}
}
} else {
TryPath.exhaustiveTypeException(tryPath.type);
}
}
return undefined;
}

18
node_modules/tsconfig-paths/src/options.ts generated vendored Normal file
View file

@ -0,0 +1,18 @@
import * as minimist from "minimist";
const argv = minimist(process.argv.slice(2), {
string: ["project"],
alias: {
project: ["P"],
},
});
const project = argv && argv.project;
export interface Options {
cwd: string;
}
export const options: Options = {
cwd: project || process.cwd(),
};

97
node_modules/tsconfig-paths/src/register.ts generated vendored Normal file
View file

@ -0,0 +1,97 @@
import { createMatchPath } from "./match-path-sync";
import { configLoader, ExplicitParams } from "./config-loader";
import { options } from "./options";
const noOp = (): void => void 0;
function getCoreModules(
builtinModules: string[] | undefined
): { [key: string]: boolean } {
builtinModules = builtinModules || [
"assert",
"buffer",
"child_process",
"cluster",
"crypto",
"dgram",
"dns",
"domain",
"events",
"fs",
"http",
"https",
"net",
"os",
"path",
"punycode",
"querystring",
"readline",
"stream",
"string_decoder",
"tls",
"tty",
"url",
"util",
"v8",
"vm",
"zlib",
];
const coreModules: { [key: string]: boolean } = {};
for (let module of builtinModules) {
coreModules[module] = true;
}
return coreModules;
}
/**
* Installs a custom module load function that can adhere to paths in tsconfig.
* Returns a function to undo paths registration.
*/
export function register(explicitParams: ExplicitParams): () => void {
const configLoaderResult = configLoader({
cwd: options.cwd,
explicitParams,
});
if (configLoaderResult.resultType === "failed") {
console.warn(
`${configLoaderResult.message}. tsconfig-paths will be skipped`
);
return noOp;
}
const matchPath = createMatchPath(
configLoaderResult.absoluteBaseUrl,
configLoaderResult.paths,
configLoaderResult.mainFields,
configLoaderResult.addMatchAll
);
// Patch node's module loading
// tslint:disable-next-line:no-require-imports variable-name
const Module = require("module");
const originalResolveFilename = Module._resolveFilename;
const coreModules = getCoreModules(Module.builtinModules);
// tslint:disable-next-line:no-any
Module._resolveFilename = function (request: string, _parent: any): string {
const isCoreModule = coreModules.hasOwnProperty(request);
if (!isCoreModule) {
const found = matchPath(request);
if (found) {
const modifiedArguments = [found, ...[].slice.call(arguments, 1)]; // Passes all arguments. Even those that is not specified above.
// tslint:disable-next-line:no-invalid-this
return originalResolveFilename.apply(this, modifiedArguments);
}
}
// tslint:disable-next-line:no-invalid-this
return originalResolveFilename.apply(this, arguments);
};
return () => {
// Return node's module loading to original state.
Module._resolveFilename = originalResolveFilename;
};
}

102
node_modules/tsconfig-paths/src/try-path.ts generated vendored Normal file
View file

@ -0,0 +1,102 @@
import * as path from "path";
import { MappingEntry } from "./mapping-entry";
import { dirname } from "path";
import { removeExtension } from "./filesystem";
export interface TryPath {
readonly type: "file" | "extension" | "index" | "package";
readonly path: string;
}
/**
* Builds a list of all physical paths to try by:
* 1. Check for file named exactly as request.
* 2. Check for files named as request ending in any of the extensions.
* 3. Check for file specified in package.json's main property.
* 4. Check for files named as request ending in "index" with any of the extensions.
*/
export function getPathsToTry(
extensions: ReadonlyArray<string>,
absolutePathMappings: ReadonlyArray<MappingEntry>,
requestedModule: string
): ReadonlyArray<TryPath> | undefined {
if (!absolutePathMappings || !requestedModule || requestedModule[0] === ".") {
return undefined;
}
const pathsToTry: Array<TryPath> = [];
for (const entry of absolutePathMappings) {
const starMatch =
entry.pattern === requestedModule
? ""
: matchStar(entry.pattern, requestedModule);
if (starMatch !== undefined) {
for (const physicalPathPattern of entry.paths) {
const physicalPath = physicalPathPattern.replace("*", starMatch);
pathsToTry.push({ type: "file", path: physicalPath });
pathsToTry.push(
...extensions.map(
(e) => ({ type: "extension", path: physicalPath + e } as TryPath)
)
);
pathsToTry.push({
type: "package",
path: path.join(physicalPath, "/package.json"),
});
const indexPath = path.join(physicalPath, "/index");
pathsToTry.push(
...extensions.map(
(e) => ({ type: "index", path: indexPath + e } as TryPath)
)
);
}
}
}
return pathsToTry.length === 0 ? undefined : pathsToTry;
}
// Not sure why we don't just return the full found path?
export function getStrippedPath(tryPath: TryPath): string {
return tryPath.type === "index"
? dirname(tryPath.path)
: tryPath.type === "file"
? tryPath.path
: tryPath.type === "extension"
? removeExtension(tryPath.path)
: tryPath.type === "package"
? tryPath.path
: exhaustiveTypeException(tryPath.type);
}
export function exhaustiveTypeException(check: never): never {
throw new Error(`Unknown type ${check}`);
}
/**
* Matches pattern with a single star against search.
* Star must match at least one character to be considered a match.
* @param patttern for example "foo*"
* @param search for example "fooawesomebar"
* @returns the part of search that * matches, or undefined if no match.
*/
function matchStar(pattern: string, search: string): string | undefined {
if (search.length < pattern.length) {
return undefined;
}
if (pattern === "*") {
return search;
}
const star = pattern.indexOf("*");
if (star === -1) {
return undefined;
}
const part1 = pattern.substring(0, star);
const part2 = pattern.substring(star + 1);
if (search.substr(0, star) !== part1) {
return undefined;
}
if (search.substr(search.length - part2.length) !== part2) {
return undefined;
}
return search.substr(star, search.length - part2.length);
}

172
node_modules/tsconfig-paths/src/tsconfig-loader.ts generated vendored Normal file
View file

@ -0,0 +1,172 @@
import * as path from "path";
import * as fs from "fs";
// tslint:disable:no-require-imports
import JSON5 = require("json5");
import StripBom = require("strip-bom");
// tslint:enable:no-require-imports
/**
* Typing for the parts of tsconfig that we care about
*/
export interface Tsconfig {
extends?: string;
compilerOptions?: {
baseUrl?: string;
paths?: { [key: string]: Array<string> };
strict?: boolean;
};
}
export interface TsConfigLoaderResult {
tsConfigPath: string | undefined;
baseUrl: string | undefined;
paths: { [key: string]: Array<string> } | undefined;
}
export interface TsConfigLoaderParams {
getEnv: (key: string) => string | undefined;
cwd: string;
loadSync?(
cwd: string,
filename?: string,
baseUrl?: string
): TsConfigLoaderResult;
}
export function tsConfigLoader({
getEnv,
cwd,
loadSync = loadSyncDefault,
}: TsConfigLoaderParams): TsConfigLoaderResult {
const TS_NODE_PROJECT = getEnv("TS_NODE_PROJECT");
const TS_NODE_BASEURL = getEnv("TS_NODE_BASEURL");
// tsconfig.loadSync handles if TS_NODE_PROJECT is a file or directory
// and also overrides baseURL if TS_NODE_BASEURL is available.
const loadResult = loadSync(cwd, TS_NODE_PROJECT, TS_NODE_BASEURL);
return loadResult;
}
function loadSyncDefault(
cwd: string,
filename?: string,
baseUrl?: string
): TsConfigLoaderResult {
// Tsconfig.loadSync uses path.resolve. This is why we can use an absolute path as filename
const configPath = resolveConfigPath(cwd, filename);
if (!configPath) {
return {
tsConfigPath: undefined,
baseUrl: undefined,
paths: undefined,
};
}
const config = loadTsconfig(configPath);
return {
tsConfigPath: configPath,
baseUrl:
baseUrl ||
(config && config.compilerOptions && config.compilerOptions.baseUrl),
paths: config && config.compilerOptions && config.compilerOptions.paths,
};
}
function resolveConfigPath(cwd: string, filename?: string): string | undefined {
if (filename) {
const absolutePath = fs.lstatSync(filename).isDirectory()
? path.resolve(filename, "./tsconfig.json")
: path.resolve(cwd, filename);
return absolutePath;
}
if (fs.statSync(cwd).isFile()) {
return path.resolve(cwd);
}
const configAbsolutePath = walkForTsConfig(cwd);
return configAbsolutePath ? path.resolve(configAbsolutePath) : undefined;
}
export function walkForTsConfig(
directory: string,
existsSync: (path: string) => boolean = fs.existsSync
): string | undefined {
const configPath = path.join(directory, "./tsconfig.json");
if (existsSync(configPath)) {
return configPath;
}
const parentDirectory = path.join(directory, "../");
// If we reached the top
if (directory === parentDirectory) {
return undefined;
}
return walkForTsConfig(parentDirectory, existsSync);
}
export function loadTsconfig(
configFilePath: string,
existsSync: (path: string) => boolean = fs.existsSync,
readFileSync: (filename: string) => string = (filename: string) =>
fs.readFileSync(filename, "utf8")
): Tsconfig | undefined {
if (!existsSync(configFilePath)) {
return undefined;
}
const configString = readFileSync(configFilePath);
const cleanedJson = StripBom(configString);
const config: Tsconfig = JSON5.parse(cleanedJson);
let extendedConfig = config.extends;
if (extendedConfig) {
if (
typeof extendedConfig === "string" &&
extendedConfig.indexOf(".json") === -1
) {
extendedConfig += ".json";
}
const currentDir = path.dirname(configFilePath);
let extendedConfigPath = path.join(currentDir, extendedConfig);
if (
extendedConfig.indexOf("/") !== -1 &&
extendedConfig.indexOf(".") !== -1 &&
!existsSync(extendedConfigPath)
) {
extendedConfigPath = path.join(
currentDir,
"node_modules",
extendedConfig
);
}
const base =
loadTsconfig(extendedConfigPath, existsSync, readFileSync) || {};
// baseUrl should be interpreted as relative to the base tsconfig,
// but we need to update it so it is relative to the original tsconfig being loaded
if (base.compilerOptions && base.compilerOptions.baseUrl) {
const extendsDir = path.dirname(extendedConfig);
base.compilerOptions.baseUrl = path.join(
extendsDir,
base.compilerOptions.baseUrl
);
}
return {
...base,
...config,
compilerOptions: {
...base.compilerOptions,
...config.compilerOptions,
},
};
}
return config;
}

View file

@ -1,46 +0,0 @@
import { assert } from "chai";
import * as Filesystem from "../src/filesystem";
import * as path from "path";
describe("filesystem", () => {
const fileThatExists = path.join(__dirname, "../package.json");
const fileThatNotExists = path.join(__dirname, "../package2.json");
it("should find file that exists, sync", () => {
const result = Filesystem.fileExistsSync(fileThatExists);
assert.equal(result, true);
});
it("should not find file that not exists, sync", () => {
const result = Filesystem.fileExistsSync(fileThatNotExists);
assert.equal(result, false);
});
it("should find file that exists, async", done => {
Filesystem.fileExistsAsync(fileThatExists, (_err, result) => {
assert.equal(result, true);
done();
});
});
it("should not find file that not exists, async", done => {
Filesystem.fileExistsAsync(fileThatNotExists, (_err, result) => {
assert.equal(result, false);
done();
});
});
it("should load json, sync", () => {
const result = Filesystem.readJsonFromDiskSync(fileThatExists);
assert.isOk(result);
assert.equal(result.main, "lib/index.js");
});
it("should load json, async", done => {
Filesystem.readJsonFromDiskAsync(fileThatExists, (_err, result) => {
assert.isOk(result);
assert.equal(result.main, "lib/index.js");
done();
});
});
});

View file

@ -1,47 +0,0 @@
import { assert } from "chai";
import { getAbsoluteMappingEntries } from "../src/mapping-entry";
import { join } from "path";
describe("mapping-entry", () => {
it("should change to absolute paths and sort in longest prefix order", () => {
const result = getAbsoluteMappingEntries(
"/absolute/base/url",
{
"*": ["/foo1", "/foo2"],
"longest/pre/fix/*": ["/foo2/bar"],
"pre/fix/*": ["/foo3"]
},
true
);
assert.deepEqual(result, [
{
pattern: "longest/pre/fix/*",
paths: [join("/absolute", "base", "url", "foo2", "bar")]
},
{
pattern: "pre/fix/*",
paths: [join("/absolute", "base", "url", "foo3")]
},
{
pattern: "*",
paths: [
join("/absolute", "base", "url", "foo1"),
join("/absolute", "base", "url", "foo2")
]
}
]);
});
it("should should add a match-all pattern when requested", () => {
let result = getAbsoluteMappingEntries("/absolute/base/url", {}, true);
assert.deepEqual(result, [
{
pattern: "*",
paths: [join("/absolute", "base", "url", "*")]
}
]);
result = getAbsoluteMappingEntries("/absolute/base/url", {}, false);
assert.deepEqual(result, []);
});
});

View file

@ -1,3 +0,0 @@
--require ts-node/register
--recursive test/
test/**/*.ts

View file

@ -1,99 +0,0 @@
import { assert } from "chai";
import { getPathsToTry } from "../src/try-path";
import { join } from "path";
describe("mapping-entry", () => {
const abosolutePathMappings = [
{
pattern: "longest/pre/fix/*",
paths: [join("/absolute", "base", "url", "foo2", "bar")]
},
{ pattern: "pre/fix/*", paths: [join("/absolute", "base", "url", "foo3")] },
{ pattern: "*", paths: [join("/absolute", "base", "url", "foo1")] }
];
it("should return no paths for relative requested module", () => {
const result = getPathsToTry(
[".ts", "tsx"],
abosolutePathMappings,
"./requested-module"
);
assert.deepEqual(result, undefined);
});
it("should return no paths if no pattern match the requested module", () => {
const result = getPathsToTry(
[".ts", "tsx"],
[
{
pattern: "longest/pre/fix/*",
paths: [join("/absolute", "base", "url", "foo2", "bar")]
},
{
pattern: "pre/fix/*",
paths: [join("/absolute", "base", "url", "foo3")]
}
],
"requested-module"
);
assert.deepEqual(result, undefined);
});
it("should get all paths that matches requested module", () => {
const result = getPathsToTry(
[".ts", ".tsx"],
abosolutePathMappings,
"longest/pre/fix/requested-module"
);
assert.deepEqual(result, [
// "longest/pre/fix/*"
{ type: "file", path: join("/absolute", "base", "url", "foo2", "bar") },
{
type: "extension",
path: join("/absolute", "base", "url", "foo2", "bar.ts")
},
{
type: "extension",
path: join("/absolute", "base", "url", "foo2", "bar.tsx")
},
{
type: "package",
path: join("/absolute", "base", "url", "foo2", "bar", "package.json")
},
{
type: "index",
path: join("/absolute", "base", "url", "foo2", "bar", "index.ts")
},
{
type: "index",
path: join("/absolute", "base", "url", "foo2", "bar", "index.tsx")
},
// "*"
{ type: "file", path: join("/absolute", "base", "url", "foo1") },
{ type: "extension", path: join("/absolute", "base", "url", "foo1.ts") },
{ type: "extension", path: join("/absolute", "base", "url", "foo1.tsx") },
{
type: "package",
path: join("/absolute", "base", "url", "foo1", "package.json")
},
{
type: "index",
path: join("/absolute", "base", "url", "foo1", "index.ts")
},
{
type: "index",
path: join("/absolute", "base", "url", "foo1", "index.tsx")
}
]);
});
});
// describe("match-star", () => {
// it("should match star in last position", () => {
// const result = matchStar("lib/*", "lib/mylib");
// assert.equal(result, "mylib");
// });
// it("should match star in first position", () => {
// const result = matchStar("*/lib", "mylib/lib");
// assert.equal(result, "mylib");
// });
// });

View file

@ -1,9 +0,0 @@
{
"extends": "../base-tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"sourceMap": true,
"outDir": "./js_out"
}
}

View file

@ -1,88 +0,0 @@
{
"rules": {
"no-any": true,
"no-internal-module": true,
"no-namespace": true,
"no-reference": true,
"no-var-requires": true,
"typedef": [true, "call-signature", "parameter", "property-declaration"],
"typedef-whitespace": [
true,
{
"call-signature": "nospace",
"index-signature": "nospace",
"parameter": "nospace",
"property-declaration": "nospace",
"variable-declaration": "nospace"
},
{
"call-signature": "onespace",
"index-signature": "onespace",
"parameter": "onespace",
"property-declaration": "onespace",
"variable-declaration": "onespace"
}
],
"curly": true,
"forin": true,
"label-position": true,
"no-arg": true,
"no-bitwise": true,
"no-conditional-assignment": true,
// "no-console": [
// true,
// "log"
// ],
"no-construct": true,
"no-debugger": true,
"no-duplicate-variable": true,
"no-empty": true,
"no-eval": true,
"no-invalid-this": true,
// "no-null-keyword": true,
"no-shadowed-variable": true,
// "no-string-literal": true,
"no-switch-case-fall-through": true,
"no-unsafe-finally": true,
"no-unused-expression": true,
"no-var-keyword": true,
"radix": true,
"switch-default": true,
"triple-equals": true,
"use-isnan": true,
"eofline": true,
"indent": [true, "spaces"],
"max-file-line-count": [true, 800],
"max-line-length": [true, 160],
"no-default-export": true,
"no-mergeable-namespace": true,
"no-require-imports": true,
"align": [true, "statements"],
//"arrow-parens": true,
"class-name": true,
"jsdoc-format": true,
"new-parens": true,
"no-angle-bracket-type-assertion": true,
"no-consecutive-blank-lines": [true, 1],
"no-parameter-properties": true,
// "object-literal-key-quotes": [
// true,
// "as-needed"
// ],
"one-line": [
true,
"check-catch",
"check-finally",
"check-else",
"check-open-brace",
"check-whitespace"
],
"one-variable-per-declaration": [true],
"variable-name": [
true,
"ban-keywords",
"check-format",
"allow-leading-underscore"
]
}
}