Skip to content

Commit

Permalink
Make cli override targets for sourcemaps
Browse files Browse the repository at this point in the history
  • Loading branch information
mischnic committed Apr 30, 2020
1 parent 864048c commit 02c5656
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 23 deletions.
5 changes: 3 additions & 2 deletions packages/core/core/src/PackagerRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,9 +460,10 @@ export default class PackagerRunner {
};

let mapKey = cacheKeys.map;
let o = bundle.target.sourceMap ?? this.options.sourceMaps;
if (
(typeof o === 'object' ? !o.inline : o) &&
(typeof bundle.target.sourceMap === 'object'
? !bundle.target.sourceMap.inline
: bundle.target.sourceMap) &&
(await this.options.cache.blobExists(mapKey))
) {
let mapStream = this.options.cache.getStream(mapKey);
Expand Down
19 changes: 16 additions & 3 deletions packages/core/core/src/TargetResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export default class TargetResolver {
scopeHoist:
this.options.scopeHoist && descriptor.scopeHoist !== false,
}),
sourceMap: descriptor.sourceMap,
sourceMap: normalizeSourceMap(this.options, descriptor.sourceMap),
};
});
}
Expand Down Expand Up @@ -351,7 +351,7 @@ export default class TargetResolver {
scopeHoist:
this.options.scopeHoist && descriptor.scopeHoist !== false,
}),
sourceMap: descriptor.sourceMap,
sourceMap: normalizeSourceMap(this.options, descriptor.sourceMap),
loc,
});
}
Expand Down Expand Up @@ -430,7 +430,7 @@ export default class TargetResolver {
scopeHoist:
this.options.scopeHoist && descriptor.scopeHoist !== false,
}),
sourceMap: descriptor.sourceMap,
sourceMap: normalizeSourceMap(this.options, descriptor.sourceMap),
loc,
});
}
Expand All @@ -450,6 +450,7 @@ export default class TargetResolver {
minify: this.options.minify,
scopeHoist: this.options.scopeHoist,
}),
sourceMap: this.options.sourceMaps ? {} : undefined,
});
}

Expand Down Expand Up @@ -577,3 +578,15 @@ function assertNoDuplicateTargets(targets, pkgFilePath, pkgContents) {
});
}
}

function normalizeSourceMap(options: ParcelOptions, sourceMap) {
if (options.sourceMaps) {
if (typeof sourceMap === 'boolean') {
return sourceMap ? {} : undefined;
} else {
return sourceMap ?? {};
}
} else {
return undefined;
}
}
26 changes: 14 additions & 12 deletions packages/core/core/test/TargetResolver.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import assert from 'assert';
import path from 'path';
import tempy from 'tempy';
import {inputFS as fs} from '@parcel/test-utils';
import {DEFAULT_OPTIONS} from './utils';
import {DEFAULT_OPTIONS as _DEFAULT_OPTIONS} from './utils';

const DEFAULT_OPTIONS = {..._DEFAULT_OPTIONS, sourceMaps: true};

import TargetResolver from '../src/TargetResolver';

Expand Down Expand Up @@ -87,7 +89,7 @@ describe('TargetResolver', () => {
minify: false,
scopeHoist: false,
},
sourceMap: undefined,
sourceMap: {},
},
{
name: 'customB',
Expand All @@ -104,7 +106,7 @@ describe('TargetResolver', () => {
minify: false,
scopeHoist: false,
},
sourceMap: undefined,
sourceMap: {},
},
],
},
Expand Down Expand Up @@ -137,7 +139,7 @@ describe('TargetResolver', () => {
minify: false,
scopeHoist: false,
},
sourceMap: undefined,
sourceMap: {},
loc: {
filePath: path.join(COMMON_TARGETS_FIXTURE_PATH, 'package.json'),
start: {
Expand Down Expand Up @@ -203,7 +205,7 @@ describe('TargetResolver', () => {
minify: false,
scopeHoist: false,
},
sourceMap: undefined,
sourceMap: {},
loc: {
filePath: path.join(COMMON_TARGETS_FIXTURE_PATH, 'package.json'),
start: {
Expand Down Expand Up @@ -298,7 +300,7 @@ describe('TargetResolver', () => {
minify: false,
scopeHoist: false,
},
sourceMap: undefined,
sourceMap: {},
loc: {
filePath: path.join(CUSTOM_TARGETS_FIXTURE_PATH, 'package.json'),
start: {
Expand Down Expand Up @@ -330,7 +332,7 @@ describe('TargetResolver', () => {
minify: false,
scopeHoist: false,
},
sourceMap: undefined,
sourceMap: {},
loc: {
filePath: path.join(CUSTOM_TARGETS_FIXTURE_PATH, 'package.json'),
start: {
Expand Down Expand Up @@ -362,7 +364,7 @@ describe('TargetResolver', () => {
minify: false,
scopeHoist: false,
},
sourceMap: undefined,
sourceMap: {},
loc: {
filePath: path.join(CUSTOM_TARGETS_FIXTURE_PATH, 'package.json'),
start: {
Expand Down Expand Up @@ -406,7 +408,7 @@ describe('TargetResolver', () => {
minify: false,
scopeHoist: false,
},
sourceMap: undefined,
sourceMap: {},
loc: {
filePath: path.join(CONTEXT_FIXTURE_PATH, 'package.json'),
start: {
Expand Down Expand Up @@ -450,7 +452,7 @@ describe('TargetResolver', () => {
minify: false,
scopeHoist: false,
},
sourceMap: undefined,
sourceMap: {},
loc: {
filePath: path.join(fixture, 'package.json'),
start: {
Expand Down Expand Up @@ -496,7 +498,7 @@ describe('TargetResolver', () => {
minify: false,
scopeHoist: false,
},
sourceMap: undefined,
sourceMap: {},
loc: {
filePath: path.join(COMMON_TARGETS_FIXTURE_PATH, 'package.json'),
start: {
Expand Down Expand Up @@ -528,7 +530,7 @@ describe('TargetResolver', () => {
minify: false,
scopeHoist: false,
},
sourceMap: undefined,
sourceMap: {},
loc: {
filePath: path.join(COMMON_TARGETS_FIXTURE_PATH, 'package.json'),
start: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
},
"targets": {
"main": false,
"app": {}
"app": {
"sourceMap": false
}
}
}
5 changes: 2 additions & 3 deletions packages/core/integration-tests/test/scope-hoisting.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ import {
getNextBuild,
} from '@parcel/test-utils';

const bundle = (name, opts = {}) =>
_bundle(name, Object.assign({scopeHoist: true}, opts));
const bundle = (name, opts = {}) => _bundle(name, {scopeHoist: true, ...opts});

const bundler = (name, opts = {}) =>
_bundler(name, Object.assign({scopeHoist: true}, opts));
_bundler(name, {scopeHoist: true, ...opts});

describe('scope hoisting', function() {
describe('es6', function() {
Expand Down
4 changes: 3 additions & 1 deletion packages/core/integration-tests/test/sourcemaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import path from 'path';
import os from 'os';
import SourceMap from '@parcel/source-map';
import {
bundle,
bundle as _bundle,
assertBundleTree,
distDir,
inputFS,
Expand All @@ -12,6 +12,8 @@ import {
} from '@parcel/test-utils';
import {loadSourceMapUrl} from '@parcel/utils';

const bundle = (name, opts = {}) => _bundle(name, {sourceMaps: true, ...opts});

function indexToLineCol(str, index) {
let beforeIndex = str.slice(0, index);
return {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/types/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export type PackageTargetDescriptor = {|
+outputFormat?: OutputFormat,
+publicUrl?: string,
+distDir?: FilePath,
+sourceMap?: TargetSourceMapOptions,
+sourceMap?: boolean | TargetSourceMapOptions,
+isLibrary?: boolean,
+minify?: boolean,
+scopeHoist?: boolean,
Expand Down

0 comments on commit 02c5656

Please sign in to comment.