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

Commit

Permalink
feat(sourcemaps): preserve prod sourcemaps out of code dir
Browse files Browse the repository at this point in the history
  • Loading branch information
mlynch committed Aug 15, 2017
1 parent 8db3be5 commit ee3e41b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/util/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ export function generateContext(context?: BuildContext): BuildContext {
setProcessEnvVar(Constants.ENV_VAR_BUILD_DIR, context.buildDir);
Logger.debug(`buildDir set to ${context.buildDir}`);

context.sourcemapDir = resolve(context.sourcemapDir || getConfigValue(context, '--sourcemapDir', null, Constants.ENV_VAR_SOURCEMAP_DIR, Constants.ENV_VAR_SOURCEMAP_DIR.toLowerCase(), Constants.SOURCEMAP_DIR));
setProcessEnvVar(Constants.ENV_VAR_SOURCEMAP_DIR, context.sourcemapDir);
Logger.debug(`sourcemapDir set to ${context.sourcemapDir}`);

context.pagesDir = resolve(context.pagesDir || getConfigValue(context, '--pagesDir', null, Constants.ENV_VAR_PAGES_DIR, Constants.ENV_VAR_PAGES_DIR.toLowerCase(), join(context.srcDir, 'pages')));
setProcessEnvVar(Constants.ENV_VAR_PAGES_DIR, context.pagesDir);
Logger.debug(`pagesDir set to ${context.pagesDir}`);
Expand Down Expand Up @@ -164,6 +168,10 @@ export function generateContext(context?: BuildContext): BuildContext {
setProcessEnvVar(Constants.ENV_VAR_SOURCE_MAP_TYPE, sourceMapTypeValue);
Logger.debug(`sourceMapType set to ${sourceMapTypeValue}`);

const moveSourceMaps = getConfigValue(context, '--moveSourceMaps', null, Constants.ENV_VAR_MOVE_SOURCE_MAPS, Constants.ENV_VAR_MOVE_SOURCE_MAPS.toLowerCase(), 'true');
setProcessEnvVar(Constants.ENV_VAR_MOVE_SOURCE_MAPS, moveSourceMaps);
Logger.debug(`moveSourceMaps set to ${moveSourceMaps}`);

const tsConfigPathValue = resolve(getConfigValue(context, '--tsconfig', null, Constants.ENV_TS_CONFIG, Constants.ENV_TS_CONFIG.toLowerCase(), join(context.rootDir, 'tsconfig.json')));
setProcessEnvVar(Constants.ENV_TS_CONFIG, tsConfigPathValue);
Logger.debug(`tsconfig set to ${tsConfigPathValue}`);
Expand Down
3 changes: 3 additions & 0 deletions src/util/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const SOURCE_MAP_TYPE_EXPENSIVE = 'source-map';
export const BUILD_DIR = 'build';
export const SRC_DIR = 'src';
export const TMP_DIR = '.tmp';
export const SOURCEMAP_DIR = '.sourcemaps';
export const WWW_DIR = 'www';
export const NODE_MODULES = 'node_modules';
export const IONIC_ANGULAR = 'ionic-angular';
Expand All @@ -35,6 +36,7 @@ export const ENV_VAR_PIPES_DIR = 'IONIC_PIPES_DIR';
export const ENV_VAR_PROVIDERS_DIR = 'IONIC_PROVIDERS_DIR';
export const ENV_VAR_TMP_DIR = 'IONIC_TMP_DIR';
export const ENV_VAR_WWW_DIR = 'IONIC_WWW_DIR';
export const ENV_VAR_SOURCEMAP_DIR = 'IONIC_SOURCEMAP_DIR';
export const ENV_VAR_HTML_TO_SERVE = 'IONIC_HTML_TO_SERVE';
export const ENV_VAR_BUILD_DIR = 'IONIC_BUILD_DIR';
export const ENV_VAR_NODE_MODULES_DIR = 'IONIC_NODE_MODULES_DIR';
Expand All @@ -50,6 +52,7 @@ export const ENV_VAR_IONIC_ANGULAR_ENTRY_POINT = 'IONIC_ANGULAR_ENTRY_POINT';
export const ENV_VAR_APP_SCRIPTS_DIR = 'IONIC_APP_SCRIPTS_DIR';
export const ENV_VAR_GENERATE_SOURCE_MAP = 'IONIC_GENERATE_SOURCE_MAP';
export const ENV_VAR_SOURCE_MAP_TYPE = 'IONIC_SOURCE_MAP_TYPE';
export const ENV_VAR_MOVE_SOURCE_MAPS = 'IONIC_MOVE_SOURCE_MAPS';
export const ENV_TS_CONFIG = 'IONIC_TS_CONFIG';
export const ENV_APP_ENTRY_POINT = 'IONIC_APP_ENTRY_POINT';
export const ENV_APP_NG_MODULE_PATH = 'IONIC_APP_NG_MODULE_PATH';
Expand Down
1 change: 1 addition & 0 deletions src/util/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export interface BuildContext {
inlineTemplates?: boolean;
webpackWatch?: any;
ionicGlobal?: any;
sourcemapDir?: string;

sassState?: BuildState;
transpileState?: BuildState;
Expand Down
17 changes: 14 additions & 3 deletions src/util/source-maps.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { join } from 'path';
import { join, relative, basename } from 'path';
import { mkdirpSync } from 'fs-extra';
import * as Constants from './constants';
import { getBooleanPropertyValue, readDirAsync, unlinkAsync } from './helpers';
import { copyFileAsync, getBooleanPropertyValue, readDirAsync, unlinkAsync } from './helpers';
import { BuildContext } from './interfaces';

export function purgeSourceMapsIfNeeded(context: BuildContext): Promise<any> {
Expand All @@ -12,8 +13,18 @@ export function purgeSourceMapsIfNeeded(context: BuildContext): Promise<any> {
const sourceMaps = fileNames.filter(fileName => fileName.endsWith('.map'));
const fullPaths = sourceMaps.map(sourceMap => join(context.buildDir, sourceMap));
const promises: Promise<void>[] = [];
const copyBeforePurge = getBooleanPropertyValue(Constants.ENV_VAR_MOVE_SOURCE_MAPS);
for (const fullPath of fullPaths) {
promises.push(unlinkAsync(fullPath));
if (copyBeforePurge) {
mkdirpSync(context.sourcemapDir)
const relativeTo = relative(fullPath, context.sourcemapDir)
const fileName = basename(fullPath)
promises.push(copyFileAsync(fullPath, join(context.sourcemapDir, fileName)).then(() => {
return unlinkAsync(fullPath)
}))
} else {
promises.push(unlinkAsync(fullPath))
}
}
return Promise.all(promises);
});
Expand Down

0 comments on commit ee3e41b

Please sign in to comment.