Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

Commit fd6bfc5

Browse files
Merge branch 'master' into tachev/fix-custom-entry-points
2 parents de10041 + 7e6619b commit fd6bfc5

13 files changed

+108
-38
lines changed

CHANGELOG.md

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
<a name="0.22.0"></a>
2+
# [0.22.0](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.21.0...0.22.0) (2019-05-15)
3+
4+
5+
### Bug Fixes
6+
7+
* ignore the Webpack runtime chunks when sending HMR updates ([be82ab7](https://github.com/NativeScript/nativescript-dev-webpack/commit/be82ab7))
8+
* show proper stack traces from uglified code (split by new line instead of semicolon) ([0ae6030](https://github.com/NativeScript/nativescript-dev-webpack/commit/0ae6030))
9+
* sourceMap not generated with Uglify ([#819](https://github.com/NativeScript/nativescript-dev-webpack/issues/819)) ([b5fd066](https://github.com/NativeScript/nativescript-dev-webpack/commit/b5fd066))
10+
* support platform specific files that are not directly imported anywhere in the app ([#843](https://github.com/NativeScript/nativescript-dev-webpack/issues/843)) ([e1e9463](https://github.com/NativeScript/nativescript-dev-webpack/commit/e1e9463))
11+
* update the css loader in order to fix a bug with leading dashes of css classes ([#847](https://github.com/NativeScript/nativescript-dev-webpack/issues/847)) ([7670e33](https://github.com/NativeScript/nativescript-dev-webpack/commit/7670e33))
12+
* **hmr:** run ts-loader in transpileOnly mode ([#878](https://github.com/NativeScript/nativescript-dev-webpack/issues/878)) ([0317729](https://github.com/NativeScript/nativescript-dev-webpack/commit/0317729))
13+
14+
15+
### Features
16+
17+
* replace UglifyJs with Terser ([621090a](https://github.com/NativeScript/nativescript-dev-webpack/commit/621090a))
18+
* support hidden source maps to map error stack traces from crash reports ([#854](https://github.com/NativeScript/nativescript-dev-webpack/issues/854)) ([dbcfbc2](https://github.com/NativeScript/nativescript-dev-webpack/commit/dbcfbc2))
19+
20+
121
<a name="0.21.2"></a>
222
## [0.21.2](https://github.com/NativeScript/nativescript-dev-webpack/compare/0.21.0...0.21.2) (2019-04-22)
323

@@ -531,7 +551,7 @@ module.exports = env => {
531551
nsWebpack.loadAdditionalPlugins({ projectDir: projectRoot }); // <----- Add this line
532552
533553
// ...
534-
```
554+
```
535555
536556
* The `getAppPath` method expects two arguments now - `platform` and `projectRoot`. The usage inside the project's `webpack.config.js` should be changed in the following way:
537557

dependencyManager.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ function getRequiredDeps(packageJson) {
8484
}
8585

8686
const deps = {
87-
"@angular/compiler-cli": "~7.2.0",
87+
"@angular/compiler-cli": "8.0.0",
8888
};
8989

9090
if (!dependsOn(packageJson, "@angular-devkit/build-angular")) {
91-
deps["@ngtools/webpack"] = "~7.2.0";
91+
deps["@ngtools/webpack"] = "8.0.0";
9292
}
9393

9494
return deps;

package.json

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nativescript-dev-webpack",
3-
"version": "0.22.0",
3+
"version": "0.24.0",
44
"main": "index",
55
"description": "",
66
"homepage": "http://www.telerik.com",
@@ -74,7 +74,7 @@
7474
"generate-android-snapshot": "./bin/generate-android-snapshot"
7575
},
7676
"dependencies": {
77-
"@angular-devkit/core": "~7.2.0",
77+
"@angular-devkit/core": "8.0.0",
7878
"clean-webpack-plugin": "~1.0.0",
7979
"copy-webpack-plugin": "~4.6.0",
8080
"css-loader": "~2.1.1",
@@ -89,7 +89,7 @@
8989
"resolve-url-loader": "~3.0.0",
9090
"sass-loader": "~7.1.0",
9191
"schema-utils": "0.4.5",
92-
"semver": "5.4.1",
92+
"semver": "^6.0.0",
9393
"shelljs": "0.6.0",
9494
"tapable": "1.0.0",
9595
"terser": "3.17.0",
@@ -101,16 +101,17 @@
101101
"webpack-sources": "~1.3.0"
102102
},
103103
"devDependencies": {
104-
"@ngtools/webpack": "~7.2.0",
105-
"@angular/compiler": "~7.2.0",
106-
"@angular/compiler-cli": "~7.2.0",
104+
"@angular/compiler": "8.0.0",
105+
"@angular/compiler-cli": "8.0.0",
106+
"@ngtools/webpack": "8.0.0",
107107
"@types/jasmine": "^3.3.7",
108108
"@types/node": "^10.12.12",
109109
"@types/proxyquire": "1.3.28",
110+
"@types/semver": "^6.0.0",
110111
"conventional-changelog-cli": "^1.3.22",
111112
"jasmine": "^3.2.0",
112113
"jasmine-spec-reporter": "^4.2.1",
113114
"proxyquire": "2.1.0",
114-
"typescript": "~3.1.1"
115+
"typescript": "~3.4.0"
115116
}
116117
}

projectHelpers.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ const isAngular = ({ projectDir, packageJson } = {}) => {
2929
.some(dependency => /^@angular\b/.test(dependency));
3030
};
3131

32+
const getAngularVersion = ({ projectDir, packageJson } = {}) => {
33+
packageJson = packageJson || getPackageJson(projectDir);
34+
35+
return packageJson.dependencies && packageJson.dependencies["@angular/core"];
36+
}
37+
3238
const isVue = ({ projectDir, packageJson } = {}) => {
3339
packageJson = packageJson || getPackageJson(projectDir);
3440

@@ -38,7 +44,14 @@ const isVue = ({ projectDir, packageJson } = {}) => {
3844

3945
const getPackageJson = projectDir => {
4046
const packageJsonPath = getPackageJsonPath(projectDir);
41-
return JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
47+
let result;
48+
try {
49+
result = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
50+
} catch (e) {
51+
result = {};
52+
}
53+
54+
return result;
4255
};
4356

4457
const writePackageJson = (content, projectDir) => {
@@ -106,6 +119,7 @@ module.exports = {
106119
isAndroid,
107120
isIos,
108121
isAngular,
122+
getAngularVersion,
109123
isVue,
110124
isTypeScript,
111125
writePackageJson,

snapshot/android/snapshot-generator.js

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const fs = require("fs");
2-
const { dirname, join } = require("path");
2+
const { dirname, join, EOL } = require("path");
33
const os = require("os");
44
const child_process = require("child_process");
55

@@ -12,6 +12,7 @@ const BUNDLE_PREAMBLE_PATH = join(__dirname, "snapshot-generator-tools/bundle-pr
1212
const BUNDLE_ENDING_PATH = join(__dirname, "snapshot-generator-tools/bundle-ending.js");
1313
const INCLUDE_GRADLE_PATH = join(__dirname, "snapshot-generator-tools/include.gradle");
1414
const MKSNAPSHOT_TOOLS_DOWNLOAD_ROOT_URL = "https://raw.githubusercontent.com/NativeScript/mksnapshot-tools/production/";
15+
const MKSNAPSHOT_TOOLS_DOWNLOAD_TIMEOUT = 60000;
1516
const SNAPSHOT_BLOB_NAME = "TNSSnapshot";
1617

1718
function shellJsExecuteInDir(dir, action) {
@@ -66,7 +67,20 @@ SnapshotGenerator.prototype.downloadMksnapshotTool = function(snapshotToolsPath,
6667

6768
const downloadUrl = MKSNAPSHOT_TOOLS_DOWNLOAD_ROOT_URL + mksnapshotToolRelativePath;
6869
createDirectory(dirname(mksnapshotToolPath));
69-
snapshotToolsDownloads[mksnapshotToolPath] = downloadFile(downloadUrl, mksnapshotToolPath);
70+
snapshotToolsDownloads[mksnapshotToolPath] = downloadFile(downloadUrl, mksnapshotToolPath, MKSNAPSHOT_TOOLS_DOWNLOAD_TIMEOUT);
71+
snapshotToolsDownloads[mksnapshotToolPath].catch(err => {
72+
const errorMessage = err && err.message ? err.message : "";
73+
let cleanupError = "";
74+
try {
75+
fs.unlinkSync(mksnapshotToolPath);
76+
} catch (unlinkErr) {
77+
if (unlinkErr && unlinkErr.code !== "ENOENT") {
78+
cleanupError = `${EOL}Failed to cleanup mksnapshot tool.`;
79+
}
80+
}
81+
82+
throw new Error(`Failed to download mksnapshot tool. Error: ${errorMessage}.${cleanupError}`);
83+
});
7084
return snapshotToolsDownloads[mksnapshotToolPath];
7185
}
7286

snapshot/android/utils.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ const CONSTANTS = {
1212

1313
const createDirectory = dir => mkdir('-p', dir);
1414

15-
const downloadFile = (url, destinationFilePath) =>
15+
const downloadFile = (url, destinationFilePath, timeout) =>
1616
new Promise((resolve, reject) => {
17-
getRequestOptions(url)
17+
getRequestOptions(url, timeout)
1818
.then(options =>
1919
get(options)
2020
.on("error", reject)
@@ -49,9 +49,9 @@ const getJsonFile = url =>
4949
).catch(reject);
5050
});
5151

52-
const getRequestOptions = (url) =>
52+
const getRequestOptions = (url, timeout) =>
5353
new Promise((resolve, reject) => {
54-
const options = { url };
54+
const options = { url, timeout };
5555
getProxySettings()
5656
.then(proxySettings => {
5757
const allOptions = Object.assign(options, proxySettings);

templates/webpack.angular.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ module.exports = env => {
9090

9191
const ngCompilerPlugin = new AngularCompilerPlugin({
9292
hostReplacementPaths: nsWebpack.getResolver([platform, "tns"]),
93-
platformTransformers: ngCompilerTransformers.map(t => t(() => ngCompilerPlugin, resolve(appFullPath, entryModule))),
93+
platformTransformers: ngCompilerTransformers.map(t => t(() => ngCompilerPlugin, resolve(appFullPath, entryModule), projectRoot)),
9494
mainPath: join(appFullPath, entryModule),
9595
tsConfigPath: join(__dirname, tsConfigName),
9696
skipCodeGeneration: !aot,

transformers/ns-replace-bootstrap.spec.ts

+16-8
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,16 @@ describe('@ngtools/webpack transformers', () => {
2121
`;
2222

2323
const { program, compilerHost } = createTypescriptContext(input);
24+
const projectDir = "/project/src/";
25+
const appModule = `${projectDir}app/app.module`;
2426
const ngCompiler = <AngularCompilerPlugin>{
2527
typeChecker: program.getTypeChecker(),
2628
entryModule: {
27-
path: '/project/src/app/app.module',
29+
path: appModule,
2830
className: 'AppModule',
2931
},
3032
};
31-
const transformer = nsReplaceBootstrap(() => ngCompiler);
33+
const transformer = nsReplaceBootstrap(() => ngCompiler, appModule, projectDir);
3234
const result = transformTypescript(undefined, [transformer], program, compilerHost);
3335

3436
expect(tags.oneLine`${result}`).toEqual(tags.oneLine`${output}`);
@@ -50,17 +52,19 @@ describe('@ngtools/webpack transformers', () => {
5052
`;
5153

5254
const { program, compilerHost } = createTypescriptContext(input);
55+
const projectDir = "/project/src/";
56+
const appModule = `${projectDir}app/app.module`;
5357
const ngCompiler: any = {
5458
_compilerOptions: {
5559
enableIvy: true
5660
},
5761
typeChecker: program.getTypeChecker(),
5862
entryModule: {
59-
path: '/project/src/app/app.module',
63+
path: appModule,
6064
className: 'AppModule',
6165
},
6266
};
63-
const transformer = nsReplaceBootstrap(() => ngCompiler);
67+
const transformer = nsReplaceBootstrap(() => ngCompiler, appModule, projectDir);
6468
const result = transformTypescript(undefined, [transformer], program, compilerHost);
6569

6670
expect(tags.oneLine`${result}`).toEqual(tags.oneLine`${output}`);
@@ -82,14 +86,16 @@ describe('@ngtools/webpack transformers', () => {
8286
`;
8387

8488
const { program, compilerHost } = createTypescriptContext(input);
89+
const projectDir = "/project/src/";
90+
const appModule = `${projectDir}app/app.module`;
8591
const ngCompiler = <AngularCompilerPlugin>{
8692
typeChecker: program.getTypeChecker(),
8793
entryModule: {
88-
path: '/project/src/app/app.module',
94+
path: appModule,
8995
className: 'AppModule',
9096
},
9197
};
92-
const transformer = nsReplaceBootstrap(() => ngCompiler);
98+
const transformer = nsReplaceBootstrap(() => ngCompiler, appModule, projectDir);
9399
const result = transformTypescript(undefined, [transformer], program, compilerHost);
94100

95101
expect(tags.oneLine`${result}`).toEqual(tags.oneLine`${output}`);
@@ -113,14 +119,16 @@ describe('@ngtools/webpack transformers', () => {
113119
`;
114120

115121
const { program, compilerHost } = createTypescriptContext(input);
122+
const projectDir = "/project/src/";
123+
const appModule = `${projectDir}app/app.module`;
116124
const ngCompiler = <AngularCompilerPlugin>{
117125
typeChecker: program.getTypeChecker(),
118126
entryModule: {
119-
path: '/project/src/app/app.module',
127+
path: appModule,
120128
className: 'AppModule',
121129
},
122130
};
123-
const transformer = nsReplaceBootstrap(() => ngCompiler);
131+
const transformer = nsReplaceBootstrap(() => ngCompiler, appModule, projectDir);
124132
const result = transformTypescript(undefined, [transformer], program, compilerHost);
125133

126134
expect(tags.oneLine`${result}`).toEqual(tags.oneLine`${output}`);

transformers/ns-replace-bootstrap.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
import { AngularCompilerPlugin } from '@ngtools/webpack';
1616
import { getResolvedEntryModule } from "../utils/transformers-utils";
1717

18-
export function nsReplaceBootstrap(getNgCompiler: () => AngularCompilerPlugin): ts.TransformerFactory<ts.SourceFile> {
18+
export function nsReplaceBootstrap(getNgCompiler: () => AngularCompilerPlugin, entryPath: string, projectDir: string): ts.TransformerFactory<ts.SourceFile> {
1919
const shouldTransform = (fileName) => !fileName.endsWith('.ngfactory.ts') && !fileName.endsWith('.ngstyle.ts');
2020
const getTypeChecker = () => getNgCompiler().typeChecker;
2121

@@ -24,7 +24,7 @@ export function nsReplaceBootstrap(getNgCompiler: () => AngularCompilerPlugin):
2424
const ngCompiler = getNgCompiler();
2525
// TODO: use something public when available
2626
const enableIvy = (<any>ngCompiler)._compilerOptions && (<any>ngCompiler)._compilerOptions.enableIvy;
27-
const entryModule = getResolvedEntryModule(ngCompiler);
27+
const entryModule = getResolvedEntryModule(ngCompiler, projectDir);
2828

2929
if (!shouldTransform(sourceFile.fileName) || !entryModule) {
3030
return ops;

transformers/ns-replace-lazy-loader.spec.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -211,14 +211,16 @@ describe("@ngtools/webpack transformers", () => {
211211
const input = tags.stripIndent`${testCase.rawAppModule}`;
212212
const output = tags.stripIndent`${testCase.transformedAppModule}`;
213213
const { program, compilerHost } = createTypescriptContext(input);
214+
const projectDir = "/project/src/";
215+
const testFile = `${projectDir}test-file`;
214216
const ngCompiler = <AngularCompilerPlugin>{
215217
typeChecker: program.getTypeChecker(),
216218
entryModule: {
217-
path: "/project/src/test-file",
219+
path: testFile,
218220
className: "AppModule",
219221
},
220222
};
221-
const transformer = nsReplaceLazyLoader(() => ngCompiler);
223+
const transformer = nsReplaceLazyLoader(() => ngCompiler, testFile, projectDir);
222224
const result = transformTypescript(undefined, [transformer], program, compilerHost);
223225

224226
expect(tags.oneLine`${result}`).toEqual(tags.oneLine`${output}`);

transformers/ns-replace-lazy-loader.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ import { AngularCompilerPlugin } from "@ngtools/webpack";
1717
import { findIdentifierNode, getObjectPropertyMatches, getDecoratorMetadata } from "../utils/ast-utils";
1818
import { getResolvedEntryModule } from "../utils/transformers-utils";
1919

20-
export function nsReplaceLazyLoader(getNgCompiler: () => AngularCompilerPlugin): ts.TransformerFactory<ts.SourceFile> {
20+
export function nsReplaceLazyLoader(getNgCompiler: () => AngularCompilerPlugin, entryPath: string, projectDir: string): ts.TransformerFactory<ts.SourceFile> {
2121
const getTypeChecker = () => getNgCompiler().typeChecker;
2222

23-
const standardTransform: StandardTransform = function(sourceFile: ts.SourceFile) {
23+
const standardTransform: StandardTransform = function (sourceFile: ts.SourceFile) {
2424
let ops: TransformOperation[] = [];
25-
const entryModule = getResolvedEntryModule(getNgCompiler());
25+
const entryModule = getResolvedEntryModule(getNgCompiler(), projectDir);
2626
const sourceFilePath = join(dirname(sourceFile.fileName), basename(sourceFile.fileName, extname(sourceFile.fileName)));
2727
if (!entryModule || normalize(sourceFilePath) !== normalize(entryModule.path)) {
2828
return ops;

transformers/ns-support-hmr-ng.spec.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,8 @@ describe("@ngtools/webpack transformers", () => {
351351
});
352352

353353
it(`${testCase.name} (in combination with AOT transformer)`, async () => {
354-
const testFile = "/project/src/test-file.ts";
354+
const projectDir = "/project/src/";
355+
const testFile = `${projectDir}test-file.ts`;
355356
const input = tags.stripIndent`${testCase.rawFile}`;
356357
const output = tags.stripIndent`${testCase.transformedFileWithAot}`;
357358
const { program, compilerHost } = createTypescriptContext(input);
@@ -363,7 +364,7 @@ describe("@ngtools/webpack transformers", () => {
363364
},
364365
};
365366

366-
const aotTransformer = nsReplaceBootstrap(() => ngCompiler);
367+
const aotTransformer = nsReplaceBootstrap(() => ngCompiler, testFile, projectDir);
367368
const hmrTransformer = nsSupportHmrNg(() => ngCompiler, testFile);
368369
const result = transformTypescript(undefined, [aotTransformer, hmrTransformer], program, compilerHost);
369370

utils/transformers-utils.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
1-
import { workaroundResolve } from "@ngtools/webpack/src/compiler_host";
21
import { AngularCompilerPlugin } from "@ngtools/webpack";
2+
import * as semver from "semver";
3+
import { getAngularVersion } from "../projectHelpers";
4+
5+
export function getResolvedEntryModule(ngCompiler: AngularCompilerPlugin, projectDir: string) {
6+
const ngCoreVersion = projectDir && semver.coerce(getAngularVersion({ projectDir }));
7+
let workaroundResolveModule;
8+
// https://github.com/angular/angular-cli/commit/d2e22e97818c6582ce4a9942c59fcac4a8aaf60e#diff-0f65e27eb122d9efa58bf08adada7f82L364
9+
if (!ngCoreVersion || semver.gte(ngCoreVersion, "8.0.0")) {
10+
workaroundResolveModule = require("@ngtools/webpack/src/utils");
11+
} else {
12+
workaroundResolveModule = require("@ngtools/webpack/src/compiler_host");
13+
}
314

4-
export function getResolvedEntryModule(ngCompiler: AngularCompilerPlugin) {
515
return ngCompiler.entryModule
6-
? { path: workaroundResolve(ngCompiler.entryModule.path), className: ngCompiler.entryModule.className }
16+
? { path: workaroundResolveModule.workaroundResolve(ngCompiler.entryModule.path), className: ngCompiler.entryModule.className }
717
: ngCompiler.entryModule;
818
}

0 commit comments

Comments
 (0)