-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
module: add --package flag for implicit config testing #38028
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, --package
really? This is technically called a “package manifest” file while “package” more broadly refers to all of the package contents as well. Can we name this flag something else?
} catch {} | ||
} | ||
const implicitPackageJSONPath = getOptionValue('--package'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I agree with @DerekNonGeneric probably package-json-file
or similar?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer not package-json
since the target could be named something like module-package.test
we could go for package-file
, does that seem fine?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think --package-config
would be preferable since that is what it is called elsewhere.
Line 1183 in 3ef9562
E('ERR_INVALID_PACKAGE_CONFIG', (path, base, message) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about --package-path
and then also making it optional to include the package.json
part?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@guybedford I'm not liking the excluding of the package.json
since it is part of the path and we don't do searching generally these days. Additionally if we are fully explicit I wonder if we could do a inline-src like @aduh95 mentioned in #37848 (comment) for other stuff. If we do searching having it map directly to a URL would be weirder.
typeof cwdPackage.string === 'string' || | ||
typeof entryPackage.string === 'string' | ||
) { | ||
throw ERR_PACKAGE_NOT_ALLOWED(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a reasonable tradeoff for now.
It isn't called a manifest anywhere in Node.js core to my knowledge. We generally call it a config. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is obviously missing a bunch of stuff (tests/docs) but I think this is a good enabler for the use case mentioned in #37857 while addressing most concerns so +1 on the solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems useful!
* @param {string} jsonPath | ||
* @param {string} srcPath | ||
*/ | ||
function clobber(jsonPath, srcPath) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about just making this set
, and then providing the direct JSON to set into the cache? Since read
is called before the usage of clobber
anyway. This then also opens the door to possible inline package configuration options.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inline package configuration??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah! (eg node app.js --pcfg.type=module
as a natural extension)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, i was imagining just allowing a source text for the file since manually configuring multiple of them would be noise for the args parser
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I wouldn't want to speculate, suggestion was as much about read + clobber = read + read + write -> read + write being the simplification.
} catch {} | ||
} | ||
const implicitPackageJSONPath = getOptionValue('--package'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about --package-path
and then also making it optional to include the package.json
part?
looks like we have some naming ideas floating around, perhaps we should try and identify the components and what they bring:
It sure does, I doubt we will ever support anything else.
This might not always be true, if we did allow URLs it would be possible to have inline sources / non-paths
Overall I like |
So, to be clear, the intention is that this flag accepts "package.json contents", and only works when no other package.json contents would be available? I don't think anyone calls package.json "config" in the ecosystem, it's just called "package.json". The file serves many purposes; it's a dependency manifest, it's config, it's metadata, etc. Why not |
Yup, that is what the discussion thread referenced seemed to lean towards as an overall potential solution to the issue. |
Seems like a good idea. Obviously there's some bikeshedding, docs, and tests needed but I'm +1 on the idea. |
cc @nodejs/modules |
I think this would be the first flag that declares its format in its name, not directly opposed since it likely will never ever change but it seems inconsistent. I think it is somewhat fine but might lead people to thinking it only works with files named
This one likely isn't a good idea to me. In particular if it states "contents" I would expect the value to be the contents and not a path to get the contents from. |
How do people feel about allowing this to be a URL (not talking HTTP support) so that |
Ah, see, i misunderstood then :-) i thought it was passing json on the command line. Isn’t the whole point of the flag to not have to make a separate file solely to add type:module? As for making it a url, that seems very strange. If we want the contents of the file to be passed inline, why not allow that directly? |
For reference, loaders are loaded by a URL rather than a path, which allows inlining:
|
@ljharb the discussion around the need for this feature is for testing purposes, it has static configuration of those |
@aduh95 I rather like that vs having 2 flags that take 2 different types which is why I think it could be useful to use here. Did you have an opinion on using a URL vs a file path? |
@bmeck my feeling is using URLs is more future proof – as you said, HTTP support is not on the table, but maybe one day. I agree that we should try to make only one flag for this. That being I don't feel strongly either way, and I'd like to hear other's opinions :) |
I've been trying to get in consistent contact with TS about this but have failed except some indirect talk. Going to start moving forward w/o their feedback. |
refs: #37857