Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Really no sourcemaps #4528

Merged
merged 4 commits into from
Apr 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/core/core/src/PackagerRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,12 @@ export default class PackagerRunner {
};

let mapKey = cacheKeys.map;
if (await this.options.cache.blobExists(mapKey)) {
if (
(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);
await writeFileStream(
outputFS,
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;
}
}
27 changes: 14 additions & 13 deletions packages/core/core/test/TargetResolver.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ 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 TargetResolver from '../src/TargetResolver';
import {DEFAULT_OPTIONS as _DEFAULT_OPTIONS} from './utils';

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

const COMMON_TARGETS_FIXTURE_PATH = path.join(
__dirname,
Expand Down Expand Up @@ -87,7 +88,7 @@ describe('TargetResolver', () => {
minify: false,
scopeHoist: false,
},
sourceMap: undefined,
sourceMap: {},
},
{
name: 'customB',
Expand All @@ -104,7 +105,7 @@ describe('TargetResolver', () => {
minify: false,
scopeHoist: false,
},
sourceMap: undefined,
sourceMap: {},
},
],
},
Expand Down Expand Up @@ -137,7 +138,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 +204,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 +299,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 +331,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 +363,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 +407,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 +451,7 @@ describe('TargetResolver', () => {
minify: false,
scopeHoist: false,
},
sourceMap: undefined,
sourceMap: {},
loc: {
filePath: path.join(fixture, 'package.json'),
start: {
Expand Down Expand Up @@ -496,7 +497,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 +529,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
18 changes: 17 additions & 1 deletion packages/core/integration-tests/test/sourcemaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ import path from 'path';
import os from 'os';
import SourceMap from '@parcel/source-map';
import {
bundle,
bundle as _bundle,
assertBundleTree,
inputFS,
outputFS,
shallowEqual,
} 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 Expand Up @@ -878,6 +880,20 @@ describe('sourcemaps', function() {
assert.deepEqual(map.sources, ['index.js']);
});

it('should respect --no-source-maps', async function() {
let b = await bundle(
path.join(__dirname, '/integration/sourcemap/index.js'),
{
sourceMaps: false,
},
);

assert.deepStrictEqual(
await outputFS.readdir(path.dirname(b.getBundles()[0].filePath)),
['index.js'],
);
});

it.skip('should load existing sourcemaps for CSS files', async function() {
async function test(minify) {
let b = await bundle(
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
2 changes: 1 addition & 1 deletion packages/packagers/js/src/JSPackager.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export default new Packager({
queue.add(async () => {
let [code, mapBuffer] = await Promise.all([
node.value.getCode(),
node.value.getMapBuffer(),
bundle.target.sourceMap && node.value.getMapBuffer(),
]);
return {code, mapBuffer};
});
Expand Down