Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

Commit 19464b3

Browse files
committed
fix(source-maps): use detailed source-map as default, fix windows path issue
1 parent 8ce3a05 commit 19464b3

File tree

5 files changed

+95
-52
lines changed

5 files changed

+95
-52
lines changed

src/util/config.ts

+72-38
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { BuildContext, TaskInfo } from './interfaces';
33
import { join, resolve } from 'path';
44
import { objectAssign } from './helpers';
55
import { FileCache } from './file-cache';
6+
import { SOURCE_MAP_TYPE_EXPENSIVE } from './constants';
7+
68
/**
79
* Create a context object which is used by all the build tasks.
810
* Filling the config data uses the following hierarchy, which will
@@ -23,6 +25,36 @@ export function generateContext(context?: BuildContext): BuildContext {
2325
context.fileCache = new FileCache();
2426
}
2527

28+
context.isProd = [
29+
context.isProd,
30+
hasArg('--prod')
31+
].find(val => typeof val === 'boolean');
32+
33+
// If context is prod then the following flags must be set to true
34+
context.runAot = [
35+
context.runAot,
36+
context.isProd || hasArg('--aot'),
37+
].find(val => typeof val === 'boolean');
38+
39+
context.runMinifyJs = [
40+
context.runMinifyJs,
41+
context.isProd || hasArg('--minifyJs')
42+
].find(val => typeof val === 'boolean');
43+
44+
context.runMinifyCss = [
45+
context.runMinifyCss,
46+
context.isProd || hasArg('--minifyCss')
47+
].find(val => typeof val === 'boolean');
48+
49+
context.optimizeJs = [
50+
context.optimizeJs,
51+
context.isProd || hasArg('--optimizeJs')
52+
].find(val => typeof val === 'boolean');
53+
54+
if (typeof context.isWatch !== 'boolean') {
55+
context.isWatch = hasArg('--watch');
56+
}
57+
2658
context.rootDir = resolve(context.rootDir || getConfigValue(context, '--rootDir', null, ENV_VAR_ROOT_DIR, ENV_VAR_ROOT_DIR.toLowerCase(), processCwd));
2759
setProcessEnvVar(ENV_VAR_ROOT_DIR, context.rootDir);
2860

@@ -42,53 +74,47 @@ export function generateContext(context?: BuildContext): BuildContext {
4274

4375
setProcessEnvVar(ENV_VAR_APP_SCRIPTS_DIR, join(__dirname, '..', '..'));
4476

45-
const sourceMapValue = getConfigValue(context, '--sourceMap', null, ENV_VAR_SOURCE_MAP, ENV_VAR_SOURCE_MAP.toLowerCase(), 'eval');
46-
setProcessEnvVar(ENV_VAR_SOURCE_MAP, sourceMapValue);
77+
const generateSourceMap = getConfigValue(context, '--generateSourceMap', null, ENV_VAR_GENERATE_SOURCE_MAP, ENV_VAR_GENERATE_SOURCE_MAP.toLowerCase(), context.isProd || context.runMinifyJs ? null : 'true');
78+
setProcessEnvVar(ENV_VAR_GENERATE_SOURCE_MAP, generateSourceMap);
4779

48-
const tsConfigPathValue = getConfigValue(context, '--tsconfigPath', null, ENV_TS_CONFIG_PATH, ENV_TS_CONFIG_PATH.toLowerCase(), join(context.rootDir, 'tsconfig.json'));
49-
setProcessEnvVar(ENV_TS_CONFIG_PATH, tsConfigPathValue);
80+
const sourceMapTypeValue = getConfigValue(context, '--sourceMapType', null, ENV_VAR_SOURCE_MAP_TYPE, ENV_VAR_SOURCE_MAP_TYPE.toLowerCase(), SOURCE_MAP_TYPE_EXPENSIVE);
81+
setProcessEnvVar(ENV_VAR_SOURCE_MAP_TYPE, sourceMapTypeValue);
5082

51-
const appEntryPointPathValue = getConfigValue(context, '--appEntryPointPath', null, ENV_APP_ENTRY_POINT_PATH, ENV_APP_ENTRY_POINT_PATH.toLowerCase(), join(context.srcDir, 'app', 'main.ts'));
52-
setProcessEnvVar(ENV_APP_ENTRY_POINT_PATH, appEntryPointPathValue);
83+
const tsConfigPathValue = getConfigValue(context, '--tsconfig', null, ENV_TS_CONFIG, ENV_TS_CONFIG.toLowerCase(), join(context.rootDir, 'tsconfig.json'));
84+
setProcessEnvVar(ENV_TS_CONFIG, tsConfigPathValue);
5385

54-
const pathToGlobUtils = getConfigValue(context, '--pathToGlobUtils', null, ENV_PATH_TO_GLOB_UTILS, ENV_PATH_TO_GLOB_UTILS.toLowerCase(), join(getProcessEnvVar(ENV_VAR_APP_SCRIPTS_DIR), 'dist', 'util', 'glob-util.js'));
55-
setProcessEnvVar(ENV_PATH_TO_GLOB_UTILS, pathToGlobUtils);
86+
const appEntryPointPathValue = getConfigValue(context, '--appEntryPoint', null, ENV_APP_ENTRY_POINT, ENV_APP_ENTRY_POINT.toLowerCase(), join(context.srcDir, 'app', 'main.ts'));
87+
setProcessEnvVar(ENV_APP_ENTRY_POINT, appEntryPointPathValue);
88+
89+
const pathToGlobUtils = getConfigValue(context, '--pathToGlobUtils', null, ENV_GLOB_UTIL, ENV_GLOB_UTIL.toLowerCase(), join(getProcessEnvVar(ENV_VAR_APP_SCRIPTS_DIR), 'dist', 'util', 'glob-util.js'));
90+
setProcessEnvVar(ENV_GLOB_UTIL, pathToGlobUtils);
5691

5792
const cleanBeforeCopy = getConfigValue(context, '--cleanBeforeCopy', null, ENV_CLEAN_BEFORE_COPY, ENV_CLEAN_BEFORE_COPY.toLowerCase(), null);
5893
setProcessEnvVar(ENV_CLEAN_BEFORE_COPY, cleanBeforeCopy);
5994

60-
if (!isValidBundler(context.bundler)) {
61-
context.bundler = bundlerStrategy(context);
62-
}
95+
const pathToClosureJar = getConfigValue(context, '--pathToClosureJar', null, ENV_CLOSURE_JAR, ENV_CLOSURE_JAR.toLowerCase(), join(getProcessEnvVar(ENV_VAR_APP_SCRIPTS_DIR), 'bin', 'closure-compiler.jar'));
96+
setProcessEnvVar(ENV_CLOSURE_JAR, pathToClosureJar);
6397

64-
context.isProd = [
65-
context.isProd,
66-
hasArg('--prod')
67-
].find(val => typeof val === 'boolean');
98+
const outputJsFileName = getConfigValue(context, '--outputJsFileName', null, ENV_OUTPUT_JS_FILE_NAME, ENV_OUTPUT_JS_FILE_NAME.toLowerCase(), 'main.js');
99+
setProcessEnvVar(ENV_OUTPUT_JS_FILE_NAME, outputJsFileName);
68100

69-
// If context is prod then the following flags must be set to true
70-
context.runAot = [
71-
context.runAot,
72-
context.isProd || hasArg('--aot'),
73-
].find(val => typeof val === 'boolean');
101+
const outputJsMapFileName = getConfigValue(context, '--outputJsMapFileName', null, ENV_OUTPUT_JS_MAP_FILE_NAME, ENV_OUTPUT_JS_MAP_FILE_NAME.toLowerCase(), 'main.js.map');
102+
setProcessEnvVar(ENV_OUTPUT_JS_MAP_FILE_NAME, outputJsMapFileName);
74103

75-
context.runMinifyJs = [
76-
context.runMinifyJs,
77-
context.isProd || hasArg('--minifyJs')
78-
].find(val => typeof val === 'boolean');
104+
const outputCssFileName = getConfigValue(context, '--outputCssFileName', null, ENV_OUTPUT_CSS_FILE_NAME, ENV_OUTPUT_CSS_FILE_NAME.toLowerCase(), 'main.css');
105+
setProcessEnvVar(ENV_OUTPUT_CSS_FILE_NAME, outputCssFileName);
79106

80-
context.runMinifyCss = [
81-
context.runMinifyCss,
82-
context.isProd || hasArg('--minifyCss')
83-
].find(val => typeof val === 'boolean');
107+
const outputCssMapFileName = getConfigValue(context, '--outputCssMapFileName', null, ENV_OUTPUT_CSS_MAP_FILE_NAME, ENV_OUTPUT_CSS_MAP_FILE_NAME.toLowerCase(), 'main.css.map');
108+
setProcessEnvVar(ENV_OUTPUT_CSS_MAP_FILE_NAME, outputCssMapFileName);
84109

85-
context.optimizeJs = [
86-
context.optimizeJs,
87-
context.isProd || hasArg('--optimizeJs')
88-
].find(val => typeof val === 'boolean');
110+
const webpackFactoryPath = getConfigValue(context, '--webpackFactoryPath', null, ENV_WEBPACK_FACTORY, ENV_WEBPACK_FACTORY.toLowerCase(), join(getProcessEnvVar(ENV_VAR_APP_SCRIPTS_DIR), 'dist', 'webpack', 'ionic-webpack-factory.js'));
111+
setProcessEnvVar(ENV_WEBPACK_FACTORY, webpackFactoryPath);
89112

90-
if (typeof context.isWatch !== 'boolean') {
91-
context.isWatch = hasArg('--watch');
113+
const ionicTypescriptLoaderPath = getConfigValue(context, '--ionicTypescriptLoaderPath', null, ENV_WEBPACK_LOADER, ENV_WEBPACK_LOADER.toLowerCase(), join(getProcessEnvVar(ENV_VAR_APP_SCRIPTS_DIR), 'dist', 'webpack', 'typescript-sourcemap-loader-memory.js'));
114+
setProcessEnvVar(ENV_WEBPACK_LOADER, ionicTypescriptLoaderPath);
115+
116+
if (!isValidBundler(context.bundler)) {
117+
context.bundler = bundlerStrategy(context);
92118
}
93119

94120
context.inlineTemplates = true;
@@ -399,11 +425,19 @@ const ENV_VAR_SRC_DIR = 'IONIC_SRC_DIR';
399425
const ENV_VAR_WWW_DIR = 'IONIC_WWW_DIR';
400426
const ENV_VAR_BUILD_DIR = 'IONIC_BUILD_DIR';
401427
const ENV_VAR_APP_SCRIPTS_DIR = 'IONIC_APP_SCRIPTS_DIR';
402-
const ENV_VAR_SOURCE_MAP = 'IONIC_SOURCE_MAP';
403-
const ENV_TS_CONFIG_PATH = 'IONIC_TS_CONFIG_PATH';
404-
const ENV_APP_ENTRY_POINT_PATH = 'IONIC_APP_ENTRY_POINT_PATH';
405-
const ENV_PATH_TO_GLOB_UTILS = 'IONIC_PATH_TO_GLOB_UTILS';
428+
const ENV_VAR_GENERATE_SOURCE_MAP = 'IONIC_GENERATE_SOURCE_MAP';
429+
const ENV_VAR_SOURCE_MAP_TYPE = 'IONIC_SOURCE_MAP_TYPE';
430+
const ENV_TS_CONFIG = 'IONIC_TS_CONFIG';
431+
const ENV_APP_ENTRY_POINT = 'IONIC_APP_ENTRY_POINT';
432+
const ENV_GLOB_UTIL = 'IONIC_GLOB_UTIL';
406433
const ENV_CLEAN_BEFORE_COPY = 'IONIC_CLEAN_BEFORE_COPY';
434+
const ENV_CLOSURE_JAR = 'IONIC_CLOSURE_JAR';
435+
const ENV_OUTPUT_JS_FILE_NAME = 'IONIC_OUTPUT_JS_FILE_NAME';
436+
const ENV_OUTPUT_JS_MAP_FILE_NAME = 'IONIC_OUTPUT_JS_MAP_FILE_NAME';
437+
const ENV_OUTPUT_CSS_FILE_NAME = 'IONIC_OUTPUT_CSS_FILE_NAME';
438+
const ENV_OUTPUT_CSS_MAP_FILE_NAME = 'IONIC_OUTPUT_CSS_MAP_FILE_NAME';
439+
const ENV_WEBPACK_FACTORY = 'IONIC_WEBPACK_FACTORY';
440+
const ENV_WEBPACK_LOADER = 'IONIC_WEBPACK_LOADER';
407441

408442
export const BUNDLER_ROLLUP = 'rollup';
409443
export const BUNDLER_WEBPACK = 'webpack';

src/util/constants.ts

+2
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ export const FILE_DELETE_EVENT = 'unlink';
44
export const DIRECTORY_ADD_EVENT = 'addDir';
55
export const DIRECTORY_DELETE_EVENT = 'unlinkDir';
66

7+
export const SOURCE_MAP_TYPE_CHEAP = 'eval';
8+
export const SOURCE_MAP_TYPE_EXPENSIVE = 'source-map';

src/util/glob-util.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import * as globFunction from 'glob';
21
import { dirname, isAbsolute, join, normalize, resolve as pathResolve, sep } from 'path';
2+
import * as globFunction from 'glob';
3+
import { toUnixPath } from './helpers';
4+
35

46
function isNegative(pattern: string) {
57
return pattern[0] === '!';
@@ -114,7 +116,7 @@ function isNegatedGlob(pattern: string) {
114116

115117
// https://github.com/jonschlinkert/to-absolute-glob/blob/master/index.js
116118
function toAbsoluteGlob(pattern: string) {
117-
const cwd = unixify(process.cwd());
119+
const cwd = toUnixPath(process.cwd());
118120

119121
// trim starting ./ from glob patterns
120122
if (pattern.slice(0, 2) === './') {
@@ -146,10 +148,6 @@ function toAbsoluteGlob(pattern: string) {
146148
return ing.negated ? '!' + pattern : pattern;
147149
}
148150

149-
function unixify(filePath: string) {
150-
return filePath.replace(/\\/g, '/');
151-
}
152-
153151
// https://github.com/es128/glob-parent/blob/master/index.js
154152
function globParent(pattern: string) {
155153
// special case for strings ending in enclosure containing path separator
@@ -160,7 +158,7 @@ function globParent(pattern: string) {
160158

161159
// remove path parts that are globby
162160
do {
163-
pattern = unixify(dirname(pattern));
161+
pattern = toUnixPath(dirname(pattern));
164162
}
165163

166164
while (isGlob(pattern) || /(^|[^\\])([\{\[]|\([^\)]+$)/.test(pattern));

src/util/helpers.ts

+4
Original file line numberDiff line numberDiff line change
@@ -203,3 +203,7 @@ export function rangeReplace(source: string, startIndex: number, endIndex: numbe
203203
export function stringSplice(source: string, startIndex: number, numToDelete: number, newContent: string) {
204204
return source.slice(0, startIndex) + newContent + source.slice(startIndex + Math.abs(numToDelete));
205205
}
206+
207+
export function toUnixPath(filePath: string) {
208+
return filePath.replace(/\\/g, '/');
209+
}

src/webpack/source-mapper.ts

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { BuildContext } from '../util/interfaces';
2-
import { getContext} from '../util/helpers';
3-
import { normalize, resolve, sep } from 'path';
2+
import { getContext, toUnixPath} from '../util/helpers';
3+
import { join, normalize, relative, resolve, sep } from 'path';
4+
import { SOURCE_MAP_TYPE_CHEAP } from '../util/constants';
45

56
export function provideCorrectSourcePath(webpackObj: any) {
67
const context = getContext();
@@ -11,9 +12,13 @@ function provideCorrectSourcePathInternal(webpackObj: any, context: BuildContext
1112
const webpackResourcePath = webpackObj.resourcePath;
1213
const noTilde = webpackResourcePath.replace(/~/g, 'node_modules');
1314
const absolutePath = resolve(normalize(noTilde));
14-
if (process.env.IONIC_SOURCE_MAP === 'eval') {
15-
// add another path.sep to the front to account for weird webpack behavior
16-
return sep + absolutePath;
15+
if (process.env.IONIC_SOURCE_MAP_TYPE === SOURCE_MAP_TYPE_CHEAP) {
16+
const mapPath = sep + absolutePath;
17+
return toUnixPath(mapPath);
1718
}
18-
return absolutePath;
19-
}
19+
// does the full map
20+
const backPath = relative(context.buildDir, context.rootDir);
21+
const relativePath = relative(context.rootDir, absolutePath);
22+
const relativeToBuildDir = join(backPath, relativePath);
23+
return toUnixPath(relativeToBuildDir);
24+
}

0 commit comments

Comments
 (0)