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

Fix: load .env value also if entry target is specified with source value in package.json #7537

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
84aede1
Fix: make each entry file refers some (virtual) file before getRootDir
Shinyaigeek Jan 7, 2022
bb1b902
Chore: add test case for .env with entry specified with package.source
Shinyaigeek Jan 7, 2022
d4170d0
Merge branch 'v2' into fix/inline-env-file-with-source-package-entry
Shinyaigeek Jan 15, 2022
4ce447e
Merge branch 'v2' into fix/inline-env-file-with-source-package-entry
Shinyaigeek Jan 18, 2022
1627b1c
Merge branch 'v2' into fix/inline-env-file-with-source-package-entry
Shinyaigeek Jan 26, 2022
6746fdf
Merge branch 'v2' into fix/inline-env-file-with-source-package-entry
Shinyaigeek Jan 28, 2022
82dad6d
Merge branch 'v2' into fix/inline-env-file-with-source-package-entry
Shinyaigeek Jan 31, 2022
0eda1b7
Merge branch 'v2' into fix/inline-env-file-with-source-package-entry
Shinyaigeek Feb 4, 2022
bb4b78c
Merge branch 'v2' into fix/inline-env-file-with-source-package-entry
Shinyaigeek Feb 10, 2022
79f6d76
Merge branch 'v2' into fix/inline-env-file-with-source-package-entry
Shinyaigeek Feb 12, 2022
81c3e8f
Merge branch 'v2' into fix/inline-env-file-with-source-package-entry
Shinyaigeek Feb 18, 2022
a725a6f
Merge branch 'v2' into fix/inline-env-file-with-source-package-entry
Shinyaigeek Feb 23, 2022
1b22141
Merge branch 'v2' into fix/inline-env-file-with-source-package-entry
Shinyaigeek Mar 1, 2022
5ea84ce
Merge branch 'v2' into fix/inline-env-file-with-source-package-entry
Shinyaigeek Mar 2, 2022
ec835d7
Merge branch 'v2' into fix/inline-env-file-with-source-package-entry
Shinyaigeek Mar 12, 2022
4dcae5c
Merge branch 'v2' into fix/inline-env-file-with-source-package-entry
Shinyaigeek Mar 13, 2022
6dd6df7
Update packages/core/integration-tests/test/javascript.js
Shinyaigeek Mar 13, 2022
4b2d4a6
Update: only resolve index when entry is file
Shinyaigeek Mar 13, 2022
d5fda50
Merge branch 'v2' into fix/inline-env-file-with-source-package-entry
Shinyaigeek Mar 20, 2022
7ea8c51
Merge branch 'v2' into fix/inline-env-file-with-source-package-entry
Shinyaigeek Mar 21, 2022
6c370bc
Update packages/core/core/src/resolveOptions.js
mischnic Mar 21, 2022
6d0ccf2
Merge branch 'v2' into fix/inline-env-file-with-source-package-entry
Shinyaigeek Mar 23, 2022
7c9d5a8
Update: handle entries specified with source in a specific case for perf
Shinyaigeek Mar 23, 2022
1201d63
Update packages/core/core/src/resolveOptions.js
mischnic Mar 23, 2022
8aae3df
Merge branch 'v2' into fix/inline-env-file-with-source-package-entry
Shinyaigeek Mar 29, 2022
4491fde
Merge branch 'v2' into fix/inline-env-file-with-source-package-entry
Shinyaigeek Mar 31, 2022
9c00171
Merge branch 'v2' into fix/inline-env-file-with-source-package-entry
Shinyaigeek Apr 2, 2022
aa4b037
Merge branch 'v2' into fix/inline-env-file-with-source-package-entry
Shinyaigeek Apr 7, 2022
9d11e6d
Merge branch 'v2' into fix/inline-env-file-with-source-package-entry
mischnic Apr 15, 2022
6ce5845
Merge branch 'v2' into fix/inline-env-file-with-source-package-entry
mischnic Apr 15, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 + '/.',
Copy link
Member

@mischnic mischnic Mar 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would break if you have extensionless entries (which should work fine right now if there's a matching glob in parcelrc).
So maybe something like this instead?

        (await inputFS.stat(entry)).isFile() ? entry : path.join(entry, 'index'),

(and use path.join(entry, 'index') instead of ./. This pattern is used in various places, for example also when determining the projectRoot a few lines further down)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! As you said, it is better to use stat than to judge with extension. I fixed in 4b2d4a6 👍

),
);

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"
}
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'),
],
},
);
Shinyaigeek marked this conversation as resolved.
Show resolved Hide resolved

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

mischnic marked this conversation as resolved.
Show resolved Hide resolved
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