Skip to content

Commit

Permalink
Merge branch 'v2' into multi-workspace-parcel-ext
Browse files Browse the repository at this point in the history
  • Loading branch information
celinanperalta committed Oct 22, 2023
2 parents 3bc3e69 + bb7ff69 commit 73c2cd7
Show file tree
Hide file tree
Showing 13 changed files with 834 additions and 276 deletions.
431 changes: 317 additions & 114 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],
"scripts": {
"build": "yarn build-bundles && cross-env NODE_ENV=production PARCEL_BUILD_ENV=production gulp",
"build-bundles": "rm -rf packages/*/*/lib && cross-env NODE_ENV=production PARCEL_BUILD_ENV=production PARCEL_SELF_BUILD=true parcel build packages/core/{fs,codeframe,package-manager,utils} packages/reporters/{cli,dev-server} packages/utils/{parcel-lsp,parcel-lsp-protocol}",
"build-bundles": "rimraf packages/*/*/lib && cross-env NODE_ENV=production PARCEL_BUILD_ENV=production PARCEL_SELF_BUILD=true parcel build packages/core/{fs,codeframe,package-manager,utils} packages/reporters/{cli,dev-server} packages/utils/{parcel-lsp,parcel-lsp-protocol}",
"build-ts": "lerna run build-ts && lerna run check-ts",
"build-native": "node scripts/build-native.js",
"build-native-release": "node scripts/build-native.js --release",
Expand Down
221 changes: 104 additions & 117 deletions packages/bundlers/default/src/DefaultBundler.js

Large diffs are not rendered by default.

216 changes: 211 additions & 5 deletions packages/core/integration-tests/test/bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
fsFixture,
run,
} from '@parcel/test-utils';
import {hashString} from '@parcel/rust';

describe('bundler', function () {
it('should not create shared bundles when a bundle is being reused and disableSharedBundles is enabled', async function () {
Expand Down Expand Up @@ -1005,6 +1006,203 @@ describe('bundler', function () {
]);
});

it('should support inline constants', async () => {
await fsFixture(overlayFS, __dirname)`
inline-constants-shared-bundles
one.html:
<script type="module" src="./one.js" />
two.html:
<script type="module" src="./two.js" />
one.js:
import {sharedFn} from './shared';
import {constant} from './constants';
sideEffectNoop('one' + sharedFn() + constant);
two.js:
import {sharedFn} from './shared';
sideEffectNoop('two' + sharedFn);
shared.js:
import {constant} from './constants.js';
export function sharedFn() {
return constant;
}
constants.js:
export const constant = 'constant';
package.json:
{
"@parcel/transformer-js": {
"unstable_inlineConstants": true
},
"@parcel/bundler-default": {
"minBundleSize": 0,
"minBundles": 3
}
}
yarn.lock:`;

let b = await bundle(
[
path.join(__dirname, 'inline-constants-shared-bundles', 'one.html'),
path.join(__dirname, 'inline-constants-shared-bundles', 'two.html'),
],
{
mode: 'production',
defaultTargetOptions: {
shouldScopeHoist: true,
sourceMaps: false,
shouldOptimize: false,
},
inputFS: overlayFS,
},
);

assertBundles(b, [
{
assets: ['one.html'],
},
{
assets: ['two.html'],
},
{
assets: ['one.js', 'shared.js', 'constants.js'],
},
{
assets: ['two.js', 'shared.js', 'constants.js'],
},
]);
});

it('should support inline constants with shared bundles', async () => {
await fsFixture(overlayFS, __dirname)`
inline-constants-shared-bundles
one.html:
<script type="module" src="./one.js" />
two.html:
<script type="module" src="./two.js" />
one.js:
import {sharedFn} from './shared';
import {constant} from './constants';
sideEffectNoop('one' + sharedFn() + constant);
two.js:
import {sharedFn} from './shared';
sideEffectNoop('two' + sharedFn);
shared.js:
import {constant} from './constants.js';
export function sharedFn() {
return constant;
}
constants.js:
export const constant = 'constant';
package.json:
{
"@parcel/transformer-js": {
"unstable_inlineConstants": true
},
"@parcel/bundler-default": {
"minBundleSize": 0
}
}
yarn.lock:`;

let b = await bundle(
[
path.join(__dirname, 'inline-constants-shared-bundles', 'one.html'),
path.join(__dirname, 'inline-constants-shared-bundles', 'two.html'),
],
{
mode: 'production',
defaultTargetOptions: {
shouldScopeHoist: true,
sourceMaps: false,
shouldOptimize: false,
},
inputFS: overlayFS,
},
);

assertBundles(b, [
{
assets: ['one.html'],
},
{
assets: ['two.html'],
},
{
assets: ['one.js', 'constants.js'],
},
{
assets: ['two.js'],
},
{
// shared bundle
assets: ['shared.js', 'constants.js'],
},
]);
});

it('should support inline constants in non-splittable bundles', async () => {
await fsFixture(overlayFS, __dirname)`
inline-constants-non-splittable
index.js:
import {sharedFn} from './shared';
sideEffectNoop(sharedFn());
shared.js:
import {constant} from './constants';
export function sharedFn() {
return constant;
}
constants.js:
export const constant = 'constant';
package.json:
{
"@parcel/transformer-js": {
"unstable_inlineConstants": true
}
}
yarn.lock:`;

let b = await bundle(
path.join(__dirname, 'inline-constants-non-splittable/index.js'),
{
mode: 'production',
defaultTargetOptions: {
shouldScopeHoist: true,
sourceMaps: false,
shouldOptimize: false,
},
inputFS: overlayFS,
},
);

assertBundles(b, [
{
assets: ['index.js', 'shared.js', 'constants.js'],
},
]);
});

describe('manual shared bundles', () => {
const dir = path.join(__dirname, 'manual-bundle');

Expand Down Expand Up @@ -1112,7 +1310,7 @@ describe('bundler', function () {
}]
}
}
.parcelrc:
{
"extends": "@parcel/config-default",
Expand All @@ -1133,14 +1331,14 @@ describe('bundler', function () {
return [asset];
}
});
index.html:
<script type="module">
import shared from './shared.js';
sideEffectNoop(shared);
sideEffectNoop(shared);
</script>
<script type="module" src="./index.js"></script>
index.js:
import shared from './shared.js';
sideEffectNoop(shared);
Expand Down Expand Up @@ -1323,6 +1521,10 @@ describe('bundler', function () {
assets: ['math.js', 'add.js', 'subtract.js'],
},
]);

let targetDistDir = __dirname.replace('/test', '/dist');
let hashedIdWithMSB = hashString('bundle:' + 'vendorjs' + targetDistDir);
assert(b.getBundles().find(b => b.id == hashedIdWithMSB));
});

it('should support manual shared bundles with constants module', async function () {
Expand Down Expand Up @@ -1388,7 +1590,7 @@ describe('bundler', function () {
],
},
{
assets: ['async.js', 'vendor-constants.js'],
assets: ['async.js'],
},
{
// Vendor MSB for JS
Expand Down Expand Up @@ -1458,6 +1660,10 @@ describe('bundler', function () {
},
]);

let targetDistDir = __dirname.replace('/test', '/dist');
let hashedIdWithMSB = hashString('bundle:' + 'vendorjs' + targetDistDir);
assert(b.getBundles().find(b => b.id == hashedIdWithMSB));

await run(b);
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
exports.foo = function() {
exports.bar()
}

exports.bar = function() {
this.baz()
}

exports.baz = function() {
return 2
}
17 changes: 17 additions & 0 deletions packages/core/integration-tests/test/scope-hoisting.js
Original file line number Diff line number Diff line change
Expand Up @@ -3574,6 +3574,23 @@ describe('scope hoisting', function () {
});

describe('commonjs', function () {
it('should wrap when this could refer to an export', async function () {
let b = await bundle(
path.join(
__dirname,
'/integration/scope-hoisting/commonjs/exports-this/a.js',
),
);

let contents = await outputFS.readFile(
b.getBundles()[0].filePath,
'utf8',
);

let wrapped = contents.includes('exports.bar()');
assert.equal(wrapped, true);
});

it('supports require of commonjs modules', async function () {
let b = await bundle(
path.join(
Expand Down
2 changes: 1 addition & 1 deletion packages/transformers/js/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
crate-type = ["rlib"]

[dependencies]
swc_core = { version = "0.83.34", features = [
swc_core = { version = "0.86.1", features = [
"common",
"common_ahash",
"common_sourcemap",
Expand Down

0 comments on commit 73c2cd7

Please sign in to comment.