Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

Commit 68d47be

Browse files
SvetoslavTsenovmanoldonev
authored andcommitted
chore: merge release in master (#804)
* docs: breaking changes/migration to 0.20.0 * docs: update breaking changes/migration (#795) * chore: bump version to 0.20.0 * fix: add a typescript module resolution when searching for the main Angular module location (#800) * feat: allow angular resolver configuration via webpack.config * feat: backwards compatible angular resolver options * chore: bump ng dependencies to match ns-angular (#801) * cut the 0.20.1 release (#803) * docs: fix tag * chore: fix version
1 parent 3ecf07a commit 68d47be

File tree

4 files changed

+71
-15
lines changed

4 files changed

+71
-15
lines changed

‎CHANGELOG.md‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
1+
<a name="0.20.1"></a>
2+
## [0.20.1](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.20.0...0.20.1) (2019年02月18日)
3+
4+
5+
### Bug Fixes
6+
7+
* add a typescript module resolution when searching for the main Angular module location ([#800](https://github.com/NativeScript/nativescript-dev-webpack/issues/800)) ([e2714f2](https://github.com/NativeScript/nativescript-dev-webpack/commit/e2714f2))
8+
9+
10+
### Features
11+
12+
* allow angular resolver configuration via webpack.config ([4f3e8a6](https://github.com/NativeScript/nativescript-dev-webpack/commit/4f3e8a6))
13+
* backwards compatible angular resolver options ([c9fc731](https://github.com/NativeScript/nativescript-dev-webpack/commit/c9fc731))
14+
15+
16+
117
<a name="0.20.0"></a>
2-
# [0.20.0](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.18.3...0.20.0) (2019年02月08日)
18+
# [0.20.0](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.19.2...0.20.0) (2019年02月08日)
319

420

521
### Bug Fixes

‎host/resolver.ts‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
import { parse, join } from "path";
22
import { statSync } from "fs";
33

4-
export function getResolver(platforms: string[], explicitResolve: string[] = []) {
5-
const platformSpecificExt = [".ts", ".js", ".scss", ".less", ".css", ".html", ".xml", ".vue", ".json"];
6-
const nsPackageFilters = [
7-
'nativescript',
8-
'tns',
9-
'ns'
10-
];
4+
export function getResolver(platforms: string[], explicitResolve?: string[], nsPackageFilters?: string[], platformSpecificExt?: string[]) {
5+
explicitResolve = explicitResolve || [];
6+
nsPackageFilters = nsPackageFilters || ['nativescript', 'tns', 'ns'];
7+
platformSpecificExt = platformSpecificExt || [".ts", ".js", ".scss", ".less", ".css", ".html", ".xml", ".vue", ".json"];
118

129
return function (path: string) {
1310
const nmIndex = path.lastIndexOf('node_modules');
@@ -16,7 +13,7 @@ export function getResolver(platforms: string[], explicitResolve: string[] = [])
1613
const subPath = path.substr(nmIndex + 'node_modules'.length).replace(/\\/g, '/');
1714
const shouldResolve = explicitResolve.length && explicitResolve.some(packageName => subPath.indexOf(packageName) !== -1);
1815
const pathParts = subPath.split(/[/\-_]/);
19-
16+
2017
if (!shouldResolve && pathParts.every(p => nsPackageFilters.every(f => f !== p))) {
2118
return path;
2219
}

‎templates/webpack.angular.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ module.exports = env => {
5151
const externals = nsWebpack.getConvertedExternals(env.externals);
5252
const appFullPath = resolve(projectRoot, appPath);
5353
const appResourcesFullPath = resolve(projectRoot, appResourcesPath);
54-
54+
consttsConfigName="tsconfig.tns.json";
5555
const entryModule = `${nsWebpack.getEntryModule(appFullPath)}.ts`;
5656
const entryPath = `.${sep}${entryModule}`;
5757
const entries = { bundle: entryPath };
@@ -73,7 +73,7 @@ module.exports = env => {
7373
// directly from node_modules and the Angular modules loader won't be able to resolve the lazy routes
7474
// fixes https://github.com/NativeScript/nativescript-cli/issues/4024
7575
if (env.externals && env.externals.indexOf("@angular/core") > -1) {
76-
const appModuleRelativePath = getMainModulePath(resolve(appFullPath, entryModule));
76+
const appModuleRelativePath = getMainModulePath(resolve(appFullPath, entryModule),tsConfigName);
7777
if (appModuleRelativePath) {
7878
const appModuleFolderPath = dirname(resolve(appFullPath, appModuleRelativePath));
7979
// include the lazy loader inside app module
@@ -87,7 +87,7 @@ module.exports = env => {
8787
hostReplacementPaths: nsWebpack.getResolver([platform, "tns"]),
8888
platformTransformers: ngCompilerTransformers.map(t => t(() => ngCompilerPlugin, resolve(appFullPath, entryModule))),
8989
mainPath: resolve(appPath, entryModule),
90-
tsConfigPath: join(__dirname, "tsconfig.tns.json"),
90+
tsConfigPath: join(__dirname, tsConfigName),
9191
skipCodeGeneration: !aot,
9292
sourceMap: !!sourceMap,
9393
additionalLazyModuleResources: additionalLazyModuleResources

‎utils/ast-utils.ts‎

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,62 @@
1414
// example of a working workaround by searching for content in each parent.
1515
// 4) Always test your transformer both single and in combinations with the other ones.
1616

17-
import { dirname, join } from "path";
17+
import { dirname, join,relative } from "path";
1818
import * as ts from "typescript";
1919
import { readFileSync, existsSync } from "fs";
2020
import { collectDeepNodes } from "@ngtools/webpack/src/transformers";
2121

22-
export function getMainModulePath(entryFilePath) {
22+
export function getMainModulePath(entryFilePath: string,tsConfigName: string) {
2323
try {
24-
return findBootstrappedModulePath(entryFilePath);
24+
// backwards compatibility
25+
tsConfigName = tsConfigName || "tsconfig.tns.json";
26+
27+
const tsModuleName = findBootstrappedModulePath(entryFilePath);
28+
const result = tsResolve(tsModuleName, entryFilePath, tsConfigName);
29+
30+
return result;
2531
} catch (e) {
2632
return null;
2733
}
2834
}
2935

36+
/**
37+
* Returns the real path to the ts/d.ts of the specified `moduleName` relative to the specified `containingFilePath`. (e.g. `~/app/file` -> `./app/file.ts`)
38+
* @param moduleName The name of the module to be resolved (e.g. `~/config.js`, `lodash`, `./already-relative.js`, `@custom-path/file`).
39+
* @param containingFilePath An absolute path to the file where the `moduleName` is imported. The relative result will be based on this file.
40+
* @param tsConfigName The name of the tsconfig which will be used during the module resolution (e.g. `tsconfig.json`).
41+
* We need this config in order to get its compiler options into account (e.g. resolve any custom `paths` like `~` or `@src`).
42+
*/
43+
function tsResolve(moduleName: string, containingFilePath: string, tsConfigName: string) {
44+
let result = moduleName;
45+
try {
46+
const parseConfigFileHost: ts.ParseConfigFileHost = {
47+
getCurrentDirectory: ts.sys.getCurrentDirectory,
48+
useCaseSensitiveFileNames: false,
49+
readDirectory: ts.sys.readDirectory,
50+
fileExists: ts.sys.fileExists,
51+
readFile: ts.sys.readFile,
52+
onUnRecoverableConfigFileDiagnostic: undefined
53+
};
54+
55+
const tsConfig = ts.getParsedCommandLineOfConfigFile(tsConfigName, ts.getDefaultCompilerOptions(), parseConfigFileHost);
56+
57+
const compilerOptions: ts.CompilerOptions = tsConfig.options || ts.getDefaultCompilerOptions();
58+
const moduleResolutionHost: ts.ModuleResolutionHost = {
59+
fileExists: ts.sys.fileExists,
60+
readFile: ts.sys.readFile
61+
};
62+
63+
const resolutionResult = ts.resolveModuleName(moduleName, containingFilePath, compilerOptions, moduleResolutionHost);
64+
65+
if (resolutionResult && resolutionResult.resolvedModule && resolutionResult.resolvedModule.resolvedFileName) {
66+
result = relative(dirname(containingFilePath), resolutionResult.resolvedModule.resolvedFileName);
67+
}
68+
} catch (err) { }
69+
70+
return result;
71+
}
72+
3073
export function findBootstrapModuleCall(mainPath: string): ts.CallExpression | null {
3174
const source = getSourceFile(mainPath);
3275

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /