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

Support for ESM plugins and configs #8913

Merged
merged 25 commits into from
Apr 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b2292bf
Resolve dev deps in ESM plugins
devongovett Feb 14, 2023
f6a96cc
workingish
devongovett Feb 16, 2023
8f062c9
wip
devongovett Feb 18, 2023
8594c2b
Handle some dynamic imports
devongovett Feb 19, 2023
c0c6e9c
Merge branch 'v2' of github.com:parcel-bundler/parcel into esm-dev-deps
devongovett Mar 26, 2023
0c7b1e8
Expand globs for expressions, only use for ESM for now
devongovett Mar 26, 2023
abb56b3
Fix deps
devongovett Mar 26, 2023
502ac9c
Add support for mjs config files
devongovett Mar 27, 2023
a6894e2
fix unit test
devongovett Mar 27, 2023
ca3d7f4
Run build before integration tests
devongovett Mar 27, 2023
5217f54
Prettier broke my code
devongovett Mar 27, 2023
2328bc6
Fix windows
devongovett Apr 1, 2023
29363f1
Clear invalidations cache
devongovett Apr 1, 2023
ff4fc8d
Merge branch 'v2' of github.com:parcel-bundler/parcel into esm-dev-deps
devongovett Apr 1, 2023
6d2f219
Load proxyrc with package manager
devongovett Apr 17, 2023
89a5397
Fix windows test output
devongovett Apr 17, 2023
a7ae15a
Try raising unit test timeout
devongovett Apr 17, 2023
654db9b
Skip file url test on windows
devongovett Apr 18, 2023
117e5e7
Merge branch 'v2' of github.com:parcel-bundler/parcel into esm-dev-deps
devongovett Apr 19, 2023
21cdd2f
More windows being a jerk
devongovett Apr 19, 2023
756a511
Update packages/utils/node-resolver-core/src/lib.rs
devongovett Apr 20, 2023
f548d06
Sync JS types for Rust module
mischnic Apr 24, 2023
8b7adda
Fix rust lint warnings
mischnic Apr 24, 2023
7c85c49
Merge branch 'v2' into esm-dev-deps
mischnic Apr 24, 2023
b0b8cf0
Remove logging
mischnic Apr 24, 2023
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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ jobs:
if: ${{matrix.os == 'ubuntu-latest'}}
- run: yarn --frozen-lockfile
- run: yarn build-native-release
- run: yarn build
mischnic marked this conversation as resolved.
Show resolved Hide resolved
- run: yarn test:integration-ci
# Similar to
# https://github.com/marketplace/actions/publish-unit-test-results#use-with-matrix-strategy
Expand Down
35 changes: 28 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ members = [
"packages/utils/hash",
"packages/optimizers/image",
"packages/utils/node-resolver-rs",
"packages/utils/node-resolver-core"
"packages/utils/node-resolver-core",
"packages/utils/dev-dep-resolver"
]
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"check": "flow check",
"lint": "eslint . && prettier \"./packages/*/*/{src,bin,test}/**/*.{js,json,md}\" --list-different && cargo fmt --all -- --check",
"prepublishOnly": "yarn adjust-versions && yarn build && yarn build-ts",
"test:unit": "cross-env NODE_ENV=test mocha && cargo test --package parcel-js-swc-core --lib",
"test:unit": "cross-env NODE_ENV=test mocha --timeout 5000 && cargo test",
"test:integration": "yarn workspace @parcel/integration-tests test",
"test:integration-ci": "yarn workspace @parcel/integration-tests test-ci",
"test": "yarn test:unit && yarn test:integration",
Expand Down
58 changes: 53 additions & 5 deletions packages/core/core/src/public/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ import type {
import type {Config, ParcelOptions} from '../types';

import invariant from 'assert';
import {DefaultWeakMap, loadConfig} from '@parcel/utils';
import path from 'path';
import {
DefaultWeakMap,
resolveConfig,
readConfig,
relativePath,
} from '@parcel/utils';
import Environment from './Environment';
import {fromProjectPath, toProjectPath} from '../projectPath';

Expand Down Expand Up @@ -149,22 +155,64 @@ export default class PublicConfig implements IConfig {
}

let parse = options && options.parse;
let conf = await loadConfig(
let configFilePath = await resolveConfig(
this.#options.inputFS,
searchPath,
fileNames,
this.#options.projectRoot,
parse == null ? null : {parse},
);
if (conf == null) {
if (configFilePath == null) {
return null;
}

let configFilePath = conf.files[0].filePath;
if (!options || !options.exclude) {
this.invalidateOnFileChange(configFilePath);
}

// If this is a JavaScript file, load it with the package manager.
let extname = path.extname(configFilePath);
if (extname === '.js' || extname === '.cjs' || extname === '.mjs') {
let specifier = relativePath(path.dirname(searchPath), configFilePath);

// Add dev dependency so we reload the config and any dependencies in watch mode.
this.addDevDependency({
specifier,
resolveFrom: searchPath,
});

// Invalidate on startup in case the config is non-deterministic,
// e.g. uses unknown environment variables, reads from the filesystem, etc.
this.invalidateOnStartup();

let config = await this.#options.packageManager.require(
specifier,
searchPath,
);

if (
// $FlowFixMe
Object.prototype.toString.call(config) === '[object Module]' &&
config.default != null
) {
// Native ESM config. Try to use a default export, otherwise fall back to the whole namespace.
config = config.default;
}

return {
contents: config,
filePath: configFilePath,
};
}

let conf = await readConfig(
this.#options.inputFS,
configFilePath,
parse == null ? null : {parse},
);
if (conf == null) {
return null;
}

return {
contents: conf.config,
filePath: configFilePath,
Expand Down
5 changes: 5 additions & 0 deletions packages/core/core/src/requests/DevDepRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export async function createDevDependency(
invalidateOnFileCreateToInternal(options.projectRoot, i),
),
invalidateOnFileChange: new Set(invalidateOnFileChangeProject),
invalidateOnStartup: invalidations.invalidateOnStartup,
additionalInvalidations,
};

Expand Down Expand Up @@ -195,6 +196,10 @@ export async function runDevDepRequest<TResult>(
api.invalidateOnFileCreate(invalidation);
}

if (devDepRequest.invalidateOnStartup) {
api.invalidateOnStartup();
}

api.storeResult({
specifier: devDepRequest.specifier,
resolveFrom: devDepRequest.resolveFrom,
Expand Down
1 change: 1 addition & 0 deletions packages/core/core/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ export type DevDepRequest = {|
hash: string,
invalidateOnFileCreate?: Array<InternalFileCreateInvalidation>,
invalidateOnFileChange?: Set<ProjectPath>,
invalidateOnStartup?: boolean,
additionalInvalidations?: Array<{|
specifier: DependencySpecifier,
resolveFrom: ProjectPath,
Expand Down