@jsverse/transloco 8.0.2 → 8.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -0
- package/README.md +4 -4
- package/esm2022/lib/transloco-fallback-strategy.mjs +3 -2
- package/esm2022/lib/transloco-lang.mjs +2 -2
- package/esm2022/lib/transloco-loading-template.mjs +3 -2
- package/esm2022/lib/transloco-missing-handler.mjs +3 -2
- package/esm2022/lib/transloco-scope.mjs +3 -2
- package/esm2022/lib/transloco-testing.module.mjs +4 -3
- package/esm2022/lib/transloco.config.mjs +4 -2
- package/esm2022/lib/transloco.interceptor.mjs +3 -2
- package/esm2022/lib/transloco.loader.mjs +3 -2
- package/esm2022/lib/transloco.service.mjs +6 -5
- package/esm2022/lib/transloco.transpiler.mjs +3 -2
- package/fesm2022/jsverse-transloco.mjs +26 -15
- package/fesm2022/jsverse-transloco.mjs.map +1 -1
- package/lib/transloco.config.d.ts +1 -0
- package/package.json +2 -2
- package/schematics/ng-add/files/transloco-loader/transloco-loader.__ts__ +1 -1
- package/schematics/ng-add/generators/http-loader.gen.d.ts +2 -1
- package/schematics/ng-add/generators/http-loader.gen.js +2 -1
- package/schematics/ng-add/generators/http-loader.gen.js.map +1 -1
- package/schematics/ng-add/index.js +70 -2
- package/schematics/ng-add/index.js.map +1 -1
- package/schematics/ng-add/ng-add.spec.js +67 -0
- package/schematics/ng-add/ng-add.spec.js.map +1 -1
- package/schematics/ng-add/schema.json +1 -1
- package/schematics-core/utils/find-module.d.ts +0 -4
- package/schematics-core/utils/find-module.js +0 -31
- package/schematics-core/utils/find-module.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsverse/transloco",
|
|
3
|
-
"version": "8.0
|
|
3
|
+
"version": "8.2.0",
|
|
4
4
|
"description": "The internationalization (i18n) library for Angular",
|
|
5
5
|
"schematics": "./schematics/collection.json",
|
|
6
6
|
"publishConfig": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"tslib": "^2.2.0",
|
|
33
33
|
"@jsverse/utils": "1.0.0-beta.5",
|
|
34
|
-
"@jsverse/transloco-utils": "^8.0
|
|
34
|
+
"@jsverse/transloco-utils": "^8.2.0"
|
|
35
35
|
},
|
|
36
36
|
"sideEffects": false,
|
|
37
37
|
"module": "fesm2022/jsverse-transloco.mjs",
|
|
@@ -7,6 +7,6 @@ export class TranslocoHttpLoader implements TranslocoLoader {
|
|
|
7
7
|
private http = inject(HttpClient);
|
|
8
8
|
|
|
9
9
|
getTranslation(lang: string) {
|
|
10
|
-
return this.http.get<Translation>(`<%= loaderPrefix
|
|
10
|
+
return this.http.get<Translation>(`<%= loaderPrefix %>/<%= urlPath %>${lang}.json`);
|
|
11
11
|
}
|
|
12
12
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export interface CreateLoaderFileParams {
|
|
2
2
|
ssr: boolean;
|
|
3
3
|
loaderPath: string;
|
|
4
|
+
urlPath: string;
|
|
4
5
|
}
|
|
5
|
-
export declare function createLoaderFile({ ssr, loaderPath }: CreateLoaderFileParams): import("@angular-devkit/schematics").Source;
|
|
6
|
+
export declare function createLoaderFile({ ssr, loaderPath, urlPath, }: CreateLoaderFileParams): import("@angular-devkit/schematics").Source;
|
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createLoaderFile = createLoaderFile;
|
|
4
4
|
const schematics_1 = require("@angular-devkit/schematics");
|
|
5
|
-
function createLoaderFile({ ssr, loaderPath }) {
|
|
5
|
+
function createLoaderFile({ ssr, loaderPath, urlPath, }) {
|
|
6
6
|
return (0, schematics_1.apply)((0, schematics_1.url)(`./files/transloco-loader`), [
|
|
7
7
|
(0, schematics_1.template)({
|
|
8
8
|
// Replace the __ts__ with ts
|
|
9
9
|
ts: 'ts',
|
|
10
10
|
loaderPrefix: ssr ? '${environment.baseUrl}' : '',
|
|
11
|
+
urlPath: urlPath,
|
|
11
12
|
}),
|
|
12
13
|
(0, schematics_1.move)('/', loaderPath),
|
|
13
14
|
]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-loader.gen.js","sourceRoot":"","sources":["../../../../../../libs/transloco/schematics/ng-add/generators/http-loader.gen.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"http-loader.gen.js","sourceRoot":"","sources":["../../../../../../libs/transloco/schematics/ng-add/generators/http-loader.gen.ts"],"names":[],"mappings":";;AAQA,4CAcC;AAtBD,2DAAwE;AAQxE,SAAgB,gBAAgB,CAAC,EAC/B,GAAG,EACH,UAAU,EACV,OAAO,GACgB;IACvB,OAAO,IAAA,kBAAK,EAAC,IAAA,gBAAG,EAAC,0BAA0B,CAAC,EAAE;QAC5C,IAAA,qBAAQ,EAAC;YACP,6BAA6B;YAC7B,EAAE,EAAE,IAAI;YACR,YAAY,EAAE,GAAG,CAAC,CAAC,CAAC,wBAAwB,CAAC,CAAC,CAAC,EAAE;YACjD,OAAO,EAAE,OAAO;SACjB,CAAC;QACF,IAAA,iBAAI,EAAC,GAAG,EAAE,UAAU,CAAC;KACtB,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -38,17 +38,84 @@ function resolveLoaderPath({ host, mainPath, isStandalone, modulePath, }) {
|
|
|
38
38
|
}
|
|
39
39
|
return resolved;
|
|
40
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Checks whether a directory "exists" in the schematic Tree.
|
|
43
|
+
*
|
|
44
|
+
* In the Angular DevKit schematic virtual file system, directories are *not real entities* —
|
|
45
|
+
* only files exist. A directory is considered to "exist" if it has at least one file or
|
|
46
|
+
* subdirectory (that itself contains files) under its path.
|
|
47
|
+
*
|
|
48
|
+
* This function returns `true` if the given directory path contains any files or subdirectories,
|
|
49
|
+
* and `false` otherwise (including for empty or nonexistent directories).
|
|
50
|
+
*
|
|
51
|
+
* @param tree - The schematic virtual file system (Tree)
|
|
52
|
+
* @param dirPath - The path to check, e.g. '/src' or '/public'
|
|
53
|
+
*/
|
|
54
|
+
function dirExists(tree, dirPath) {
|
|
55
|
+
const dir = tree.getDir(dirPath);
|
|
56
|
+
return dir.subfiles.length > 0 || dir.subdirs.length > 0;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Detects the appropriate path for translation assets based on Angular project structure.
|
|
60
|
+
*
|
|
61
|
+
* Angular 18+ introduced a new project structure using a top-level `public/` directory instead
|
|
62
|
+
* of `src/assets/` for static assets. This function implements a three-tier detection strategy
|
|
63
|
+
* to determine where translation JSON files should be placed:
|
|
64
|
+
*
|
|
65
|
+
* 1. **Directory existence check**: If `/public` exists, assume Angular 18+ structure
|
|
66
|
+
* 2. **Legacy assets check**: If `${sourceRoot}/assets` exists, use traditional structure
|
|
67
|
+
* 3. **Version fallback**: Parse package.json @angular/core version as final determination
|
|
68
|
+
*
|
|
69
|
+
* The detection accounts for the fact that in schematics, we're working with a virtual file
|
|
70
|
+
* system where directories only "exist" if they contain files, and we need to make the right
|
|
71
|
+
* choice for where users expect their translation files to be placed.
|
|
72
|
+
*
|
|
73
|
+
* @param host - The schematic virtual file system (Tree)
|
|
74
|
+
* @param sourceRoot - The source root path (typically 'src' or 'projects/app-name/src')
|
|
75
|
+
* @returns The detected assets path, e.g. 'public/i18n/' or 'src/assets/i18n/'
|
|
76
|
+
*/
|
|
77
|
+
function detectAssetsPath(host, sourceRoot) {
|
|
78
|
+
var _a, _b;
|
|
79
|
+
if (dirExists(host, '/public')) {
|
|
80
|
+
return 'public/i18n/';
|
|
81
|
+
}
|
|
82
|
+
if (dirExists(host, `${sourceRoot}/assets`)) {
|
|
83
|
+
return `${sourceRoot}/assets/i18n/`;
|
|
84
|
+
}
|
|
85
|
+
// Fallback: Check package.json for Angular version
|
|
86
|
+
try {
|
|
87
|
+
const packageJson = JSON.parse(host.read('/package.json').toString());
|
|
88
|
+
const version = ((_a = packageJson.dependencies) === null || _a === void 0 ? void 0 : _a['@angular/core']) ||
|
|
89
|
+
((_b = packageJson.devDependencies) === null || _b === void 0 ? void 0 : _b['@angular/core']);
|
|
90
|
+
// Extract major version number from versions like "^18.2.0", "~17.0.0", ">=16.0.0", etc.
|
|
91
|
+
const majorVersionMatch = version === null || version === void 0 ? void 0 : version.match(/(\d+)\./);
|
|
92
|
+
const majorVersion = parseInt(majorVersionMatch[1]);
|
|
93
|
+
return majorVersion >= 18 ? 'public/i18n/' : `${sourceRoot}/assets/i18n/`;
|
|
94
|
+
}
|
|
95
|
+
catch (_c) {
|
|
96
|
+
return `${sourceRoot}/assets/i18n/`; // Safe default
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function getUrlPathFromAssetsPath(assetsPath) {
|
|
100
|
+
if (assetsPath.startsWith('public/')) {
|
|
101
|
+
return assetsPath.replace('public/', '');
|
|
102
|
+
}
|
|
103
|
+
return assetsPath;
|
|
104
|
+
}
|
|
41
105
|
function ngAdd(options) {
|
|
42
106
|
return (host, context) => __awaiter(this, void 0, void 0, function* () {
|
|
43
107
|
var _a;
|
|
44
108
|
const langs = options.langs.split(',').map((l) => l.trim());
|
|
45
109
|
if (!options.project) {
|
|
46
|
-
throw new schematics_1.SchematicsException('Project name is required.
|
|
110
|
+
throw new schematics_1.SchematicsException('Project name is required. You must explicitly provide the project name using --project=<project-name>');
|
|
47
111
|
}
|
|
48
112
|
const project = (0, schematics_core_1.getProject)(host, options.project);
|
|
49
113
|
const sourceRoot = (_a = project.sourceRoot) !== null && _a !== void 0 ? _a : 'src';
|
|
50
114
|
const isLib = project.projectType === 'library';
|
|
51
|
-
const assetsPath =
|
|
115
|
+
const assetsPath = options.path
|
|
116
|
+
? `${sourceRoot}/${options.path}`
|
|
117
|
+
: detectAssetsPath(host, sourceRoot);
|
|
118
|
+
const urlPath = getUrlPathFromAssetsPath(assetsPath);
|
|
52
119
|
const mainPath = yield (0, util_1.getMainFilePath)(host, options.project);
|
|
53
120
|
const isStandalone = (0, ng_ast_utils_1.isStandaloneApp)(host, mainPath);
|
|
54
121
|
const modulePath = isStandalone
|
|
@@ -71,6 +138,7 @@ function ngAdd(options) {
|
|
|
71
138
|
actions.push((0, schematics_1.mergeWith)((0, http_loader_gen_1.createLoaderFile)({
|
|
72
139
|
ssr: options.ssr,
|
|
73
140
|
loaderPath,
|
|
141
|
+
urlPath,
|
|
74
142
|
})));
|
|
75
143
|
}
|
|
76
144
|
const hasTranslationFiles = (0, schematics_core_1.checkIfTranslationFilesExist)(assetsPath, langs, '.json', true);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/transloco/schematics/ng-add/index.ts"],"names":[],"mappings":";;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/transloco/schematics/ng-add/index.ts"],"names":[],"mappings":";;;;;;;;;;;AAgJA,sBAmHC;AAnQD,yCAAoC;AAEpC,2DAOoC;AACpC,2EAGkD;AAClD,sEAGqD;AACrD,wEAGsD;AACtD,kFAAkF;AAElF,2DAO+B;AAE/B,qCAAkD;AAClD,kEAAgE;AAChE,kEAAqE;AAErE,SAAS,wBAAwB,CAC/B,IAAU,EACV,UAAkB,EAClB,YAAoB;IAEpB,MAAM,QAAQ,GAAG;cACL,YAAY,IAAI,CAAC;IAE7B,IAAA,iCAAe,EAAC,IAAI,EAAE,UAAU,EAAE,CAAC,GAAW,EAAE,EAAE,CAChD,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAC3B,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,qBAAqB,EAAE,QAAQ,CAAC;QAC9C,CAAC,CAAC,GAAG,CACR,CAAC;AACJ,CAAC;AASD,SAAS,iBAAiB,CAAC,EACzB,IAAI,EACJ,QAAQ,EACR,YAAY,EACZ,UAAU,GACc;;IACxB,IAAI,QAAQ,GAAG,UAAU,CAAC;IAC1B,IAA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;QACtE,CAAC;QAED,IAAA,oCAAkB,EAAC,IAAI,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC;QAE5C,OAAO,IAAA,kBAAK,EAAC,OAAO,CAAC,CAAC,IAAI,EAAE,OAAO,CAAS,CAAC;IAC/C,CAAC,CAAA,CAAC;AACJ,CAAC"}
|
|
@@ -38,6 +38,73 @@ describe('ng add', () => {
|
|
|
38
38
|
expect(readFile(tree, 'app/app.config.ts')).toContain('provideTransloco(');
|
|
39
39
|
}));
|
|
40
40
|
});
|
|
41
|
+
describe('Folder Detection', () => {
|
|
42
|
+
it('should use public/i18n for Angular 18+ projects with public folder', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
+
const options = { project: 'bar' };
|
|
44
|
+
const initialTree = yield (0, testing_2.createWorkspace)(schematicRunner);
|
|
45
|
+
// Create public folder to simulate Angular 18+
|
|
46
|
+
initialTree.create('/public/favicon.ico', '');
|
|
47
|
+
const tree = yield schematicRunner.runSchematic('ng-add', options, initialTree);
|
|
48
|
+
expect(tree.files).toContain('/public/i18n/en.json');
|
|
49
|
+
expect(tree.files).toContain('/public/i18n/es.json');
|
|
50
|
+
// Check that loader uses correct URL path
|
|
51
|
+
const loaderContent = readFile(tree, 'app/transloco-loader.ts');
|
|
52
|
+
expect(loaderContent).toContain('/i18n/${lang}.json');
|
|
53
|
+
expect(loaderContent).not.toContain('/assets/i18n/');
|
|
54
|
+
}));
|
|
55
|
+
it('should use src/assets/i18n for projects with assets folder', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
56
|
+
const options = { project: 'bar' };
|
|
57
|
+
const initialTree = yield (0, testing_2.createWorkspace)(schematicRunner);
|
|
58
|
+
// Create assets folder to simulate traditional Angular structure
|
|
59
|
+
initialTree.create('/projects/bar/src/assets/icons/icon.png', '');
|
|
60
|
+
const tree = yield schematicRunner.runSchematic('ng-add', options, initialTree);
|
|
61
|
+
expect(tree.files).toContain('/projects/bar/src/assets/i18n/en.json');
|
|
62
|
+
expect(tree.files).toContain('/projects/bar/src/assets/i18n/es.json');
|
|
63
|
+
// Check that loader uses correct URL path
|
|
64
|
+
const loaderContent = readFile(tree, 'app/transloco-loader.ts');
|
|
65
|
+
expect(loaderContent).toContain('/assets/i18n/${lang}.json');
|
|
66
|
+
}));
|
|
67
|
+
it('should respect custom path when specified', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
68
|
+
const options = {
|
|
69
|
+
project: 'bar',
|
|
70
|
+
path: 'custom/translations/',
|
|
71
|
+
};
|
|
72
|
+
const tree = yield schematicRunner.runSchematic('ng-add', options, yield (0, testing_2.createWorkspace)(schematicRunner));
|
|
73
|
+
expect(tree.files).toContain('/projects/bar/src/custom/translations/en.json');
|
|
74
|
+
expect(tree.files).toContain('/projects/bar/src/custom/translations/es.json');
|
|
75
|
+
// Check that loader uses correct URL path
|
|
76
|
+
const loaderContent = readFile(tree, 'app/transloco-loader.ts');
|
|
77
|
+
expect(loaderContent).toContain('/custom/translations/${lang}.json');
|
|
78
|
+
}));
|
|
79
|
+
it('should fallback to package.json version detection when folders are ambiguous', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
80
|
+
const options = { project: 'bar' };
|
|
81
|
+
const initialTree = yield (0, testing_2.createWorkspace)(schematicRunner);
|
|
82
|
+
// Simulate Angular 18+ by updating package.json
|
|
83
|
+
const packageJson = JSON.parse(initialTree.read('/package.json').toString());
|
|
84
|
+
packageJson.dependencies['@angular/core'] = '^18.0.0';
|
|
85
|
+
initialTree.overwrite('/package.json', JSON.stringify(packageJson, null, 2));
|
|
86
|
+
const tree = yield schematicRunner.runSchematic('ng-add', options, initialTree);
|
|
87
|
+
expect(tree.files).toContain('/public/i18n/en.json');
|
|
88
|
+
expect(tree.files).toContain('/public/i18n/es.json');
|
|
89
|
+
// Check that loader uses correct URL path for Angular 18+
|
|
90
|
+
const loaderContent = readFile(tree, 'app/transloco-loader.ts');
|
|
91
|
+
expect(loaderContent).toContain('/i18n/${lang}.json');
|
|
92
|
+
}));
|
|
93
|
+
it('should fallback to assets for Angular <18 when package.json indicates older version', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
94
|
+
const options = { project: 'bar' };
|
|
95
|
+
const initialTree = yield (0, testing_2.createWorkspace)(schematicRunner);
|
|
96
|
+
// Simulate Angular 17 by updating package.json
|
|
97
|
+
const packageJson = JSON.parse(initialTree.read('/package.json').toString());
|
|
98
|
+
packageJson.dependencies['@angular/core'] = '^17.0.0';
|
|
99
|
+
initialTree.overwrite('/package.json', JSON.stringify(packageJson, null, 2));
|
|
100
|
+
const tree = yield schematicRunner.runSchematic('ng-add', options, initialTree);
|
|
101
|
+
expect(tree.files).toContain('/projects/bar/src/assets/i18n/en.json');
|
|
102
|
+
expect(tree.files).toContain('/projects/bar/src/assets/i18n/es.json');
|
|
103
|
+
// Check that loader uses correct URL path for Angular <18
|
|
104
|
+
const loaderContent = readFile(tree, 'app/transloco-loader.ts');
|
|
105
|
+
expect(loaderContent).toContain('/assets/i18n/${lang}.json');
|
|
106
|
+
}));
|
|
107
|
+
});
|
|
41
108
|
});
|
|
42
109
|
function readFile(host, path) {
|
|
43
110
|
return host.get(`/projects/bar/src/${path}`).content.toString();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ng-add.spec.js","sourceRoot":"","sources":["../../../../../libs/transloco/schematics/ng-add/ng-add.spec.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,sCAAsC;AAEtC,gEAG4C;AAE5C,2DAAgE;AAIhE,MAAM,cAAc,GAAG,QAAQ,CAAC,IAAI,CAAC,SAAS,EAAE,oBAAoB,CAAC,CAAC;AAEtE,QAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE;IACtB,MAAM,eAAe,GAAG,IAAI,6BAAmB,CAAC,YAAY,EAAE,cAAc,CAAC,CAAC;IAE9E,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;QACzB,EAAE,CAAC,2CAA2C,EAAE,GAAS,EAAE;YACzD,MAAM,OAAO,GAAkB,EAAE,OAAO,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AI,CAAC,GAAG,CAAC,qBAAqB,IAAI,EAAE,CAAE,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;AACnE,CAAC"}
|
|
@@ -9,10 +9,6 @@ import { Path } from '@angular-devkit/core';
|
|
|
9
9
|
import { Tree } from '@angular-devkit/schematics';
|
|
10
10
|
export declare const MODULE_EXT = ".module.ts";
|
|
11
11
|
export declare const ROUTING_MODULE_EXT = "-routing.module.ts";
|
|
12
|
-
/**
|
|
13
|
-
* Find the module referred by a set of options passed to the schematics.
|
|
14
|
-
*/
|
|
15
|
-
export declare function findRootModule(host: Tree, module: string, rootPath?: string, skipImport?: boolean): string | undefined;
|
|
16
12
|
/**
|
|
17
13
|
* Find the module referred by a set of options passed to the schematics.
|
|
18
14
|
*/
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ROUTING_MODULE_EXT = exports.MODULE_EXT = void 0;
|
|
4
|
-
exports.findRootModule = findRootModule;
|
|
5
4
|
exports.findModuleFromOptions = findModuleFromOptions;
|
|
6
5
|
exports.findModule = findModule;
|
|
7
6
|
/* eslint-disable */
|
|
@@ -16,26 +15,6 @@ exports.findModule = findModule;
|
|
|
16
15
|
const core_1 = require("@angular-devkit/core");
|
|
17
16
|
exports.MODULE_EXT = '.module.ts';
|
|
18
17
|
exports.ROUTING_MODULE_EXT = '-routing.module.ts';
|
|
19
|
-
/**
|
|
20
|
-
* Find the module referred by a set of options passed to the schematics.
|
|
21
|
-
*/
|
|
22
|
-
function findRootModule(host, module, rootPath = '', skipImport = false) {
|
|
23
|
-
if (skipImport || !module) {
|
|
24
|
-
return undefined;
|
|
25
|
-
}
|
|
26
|
-
const modulePath = (0, core_1.normalize)(`${rootPath}/${module}`);
|
|
27
|
-
const matchingExt = [
|
|
28
|
-
'',
|
|
29
|
-
'.ts',
|
|
30
|
-
exports.MODULE_EXT,
|
|
31
|
-
`/${module}${exports.MODULE_EXT}`,
|
|
32
|
-
`/${module}.ts`,
|
|
33
|
-
].find((ext) => host.exists(modulePath + ext));
|
|
34
|
-
if (matchingExt) {
|
|
35
|
-
return (0, core_1.normalize)(modulePath + matchingExt);
|
|
36
|
-
}
|
|
37
|
-
throw new Error(`Specified module path ${modulePath} does not exist`);
|
|
38
|
-
}
|
|
39
18
|
/**
|
|
40
19
|
* Find the module referred by a set of options passed to the schematics.
|
|
41
20
|
*/
|
|
@@ -76,8 +55,6 @@ function findModuleFromOptions(host, options, projectPath) {
|
|
|
76
55
|
}
|
|
77
56
|
}
|
|
78
57
|
return null;
|
|
79
|
-
throw new Error(`Specified module '${options.module}' does not exist.\n` +
|
|
80
|
-
`Looked in the following directories:\n ${candidatesDirs.join('\n ')}`);
|
|
81
58
|
}
|
|
82
59
|
}
|
|
83
60
|
/**
|
|
@@ -96,17 +73,9 @@ function findModule(host, generateDir, moduleExt = exports.MODULE_EXT, routingMo
|
|
|
96
73
|
}
|
|
97
74
|
else if (filteredMatches.length > 1) {
|
|
98
75
|
return null;
|
|
99
|
-
throw new Error('More than one module matches. Use skip-import option to skip importing ' +
|
|
100
|
-
'the component into the closest module.');
|
|
101
76
|
}
|
|
102
77
|
dir = dir.parent;
|
|
103
78
|
}
|
|
104
|
-
const errorMsg = foundRoutingModule
|
|
105
|
-
? 'Could not find a non Routing NgModule.' +
|
|
106
|
-
`\nModules with suffix '${routingModuleExt}' are strictly reserved for routing.` +
|
|
107
|
-
'\nUse the skip-import option to skip importing in NgModule.'
|
|
108
|
-
: 'Could not find an NgModule. Use the skip-import option to skip importing in NgModule.';
|
|
109
79
|
return null;
|
|
110
|
-
throw new Error(errorMsg);
|
|
111
80
|
}
|
|
112
81
|
//# sourceMappingURL=find-module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"find-module.js","sourceRoot":"","sources":["../../../../../libs/transloco/schematics-core/utils/find-module.ts"],"names":[],"mappings":";;;AAwBA,
|
|
1
|
+
{"version":3,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