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

Commit 4238daf

Browse files
committed
fix: move a typescript specific logic in ast utils in order to avoid invalid import in JS applications
1 parent 73411d8 commit 4238daf

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

Diff for: index.js

-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const path = require("path");
22
const { existsSync } = require("fs");
3-
const { findBootstrapModulePath } = require("./utils/ast-utils");
43
const { ANDROID_APP_PATH } = require("./androidProjectHelpers");
54
const {
65
getPackageJson,
@@ -41,14 +40,6 @@ exports.getEntryModule = function (appDirectory) {
4140
return entry;
4241
};
4342

44-
exports.getMainModulePath = function (entryFilePath) {
45-
try {
46-
return findBootstrapModulePath(entryFilePath);
47-
} catch (e) {
48-
return null;
49-
}
50-
}
51-
5243
exports.getAppPath = (platform, projectDir) => {
5344
if (isIos(platform)) {
5445
const appName = path.basename(projectDir);

Diff for: templates/webpack.angular.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const nsWebpack = require("nativescript-dev-webpack");
55
const nativescriptTarget = require("nativescript-dev-webpack/nativescript-target");
66
const { nsReplaceBootstrap } = require("nativescript-dev-webpack/transformers/ns-replace-bootstrap");
77
const { nsReplaceLazyLoader } = require("nativescript-dev-webpack/transformers/ns-replace-lazy-loader");
8+
const { getMainModulePath } = require("nativescript-dev-webpack/utils/ast-utils");
89
const CleanWebpackPlugin = require("clean-webpack-plugin");
910
const CopyWebpackPlugin = require("copy-webpack-plugin");
1011
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
@@ -65,7 +66,7 @@ module.exports = env => {
6566
// directly from node_modules and the Angular modules loader won't be able to resolve the lazy routes
6667
// fixes https://github.com/NativeScript/nativescript-cli/issues/4024
6768
if (env.externals.indexOf("@angular/core") > -1) {
68-
const appModuleRelativePath = nsWebpack.getMainModulePath(resolve(appFullPath, entryModule));
69+
const appModuleRelativePath = getMainModulePath(resolve(appFullPath, entryModule));
6970
if (appModuleRelativePath) {
7071
const appModuleFolderPath = dirname(resolve(appFullPath, appModuleRelativePath));
7172
// include the lazy loader inside app module

Diff for: utils/ast-utils.ts

+8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ import * as ts from "typescript";
88
import { readFileSync, existsSync } from "fs";
99
import { collectDeepNodes } from "@ngtools/webpack/src/transformers";
1010

11+
export function getMainModulePath(entryFilePath) {
12+
try {
13+
return findBootstrapModulePath(entryFilePath);
14+
} catch (e) {
15+
return null;
16+
}
17+
}
18+
1119
export function findBootstrapModuleCall(mainPath: string): ts.CallExpression | null {
1220
if (!existsSync(mainPath)) {
1321
throw new Error(`Main file (${mainPath}) not found`);

0 commit comments

Comments
 (0)