Skip to content

Commit

Permalink
Merge branch 'v2' of https://github.com/Shinyaigeek/parcel into v2
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinyaigeek committed Mar 20, 2022
2 parents ef16fad + 06f6d38 commit 0e3f3bd
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/core/core/src/resolveOptions.js
Expand Up @@ -49,7 +49,15 @@ export default async function resolveOptions(
entries = [path.resolve(inputCwd, initialOptions.entries)];
}

let entryRoot = getRootDir(entries);
let entryRoot = getRootDir(
entries.map(entry =>
// if the entry refers entryRootDir, getRootDir returns the parent directory of entryRootDir.
// In this case, each entry should refers some file, but without cli build target entry refers entryRootDir directory.
// So, we add /. to entry to make entry refers some (virtual) file in such case.
path.extname(entry) !== '' ? entry : entry + '/.',
),
);

let projectRootFile =
(await resolveConfig(
inputFS,
Expand Down
@@ -0,0 +1,2 @@
FOO=bar
BAR=test
@@ -0,0 +1 @@
module.exports = process.env.FOO + process.env.BAR;
@@ -0,0 +1,4 @@
{
"name": "env-file-with-package-source",
"source": "index.js"
}
Empty file.
20 changes: 20 additions & 0 deletions packages/core/integration-tests/test/javascript.js
Expand Up @@ -2955,6 +2955,26 @@ describe('javascript', function () {
assert.equal(output, 'barbaz');
});

it('should insert environment variables from a file even if entry file is specified with source value in package.json', async function () {
let b = await bundle(
path.join(
__dirname,
'/integration/env-file-with-package-source/index.js',
),
{
// when the entry file is specified with a source value in package.json and not specified with cli build target value,
// the entry file is resolved to the entry root directory in packages/core/core/src/resolveOptions.js as InitialParcelOptions.
// So, entry root directory is specified as InitialParcelOptions' entries value.
entries: [
path.join(__dirname, '/integration/env-file-with-package-source'),
],
},
);

let output = await run(b);
assert.equal(output, 'bartest');
});

it('should error on process.env mutations', async function () {
let filePath = path.join(__dirname, '/integration/env-mutate/index.js');
await assert.rejects(bundle(filePath), {
Expand Down

0 comments on commit 0e3f3bd

Please sign in to comment.