-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
module: add --package flag for implicit config testing #38028
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,10 @@ const { | |
const { reconnectZeroFillToggle } = require('internal/buffer'); | ||
|
||
const { Buffer } = require('buffer'); | ||
const { ERR_MANIFEST_ASSERT_INTEGRITY } = require('internal/errors').codes; | ||
const { | ||
ERR_MANIFEST_ASSERT_INTEGRITY, | ||
ERR_PACKAGE_NOT_ALLOWED | ||
} = require('internal/errors').codes; | ||
const assert = require('internal/assert'); | ||
|
||
function prepareMainThreadExecution(expandArgv1 = false) { | ||
|
@@ -97,14 +100,34 @@ function patchProcessObject(expandArgv1) { | |
}); | ||
process.argv[0] = process.execPath; | ||
|
||
let base; | ||
if (expandArgv1 && process.argv[1] && | ||
!StringPrototypeStartsWith(process.argv[1], '-')) { | ||
// Expand process.argv[1] into a full path. | ||
const path = require('path'); | ||
try { | ||
process.argv[1] = path.resolve(process.argv[1]); | ||
base = path.dirname(process.argv[1]); | ||
} catch {} | ||
} | ||
const implicitPackageJSONPath = getOptionValue('--package'); | ||
if (implicitPackageJSONPath) { | ||
const cwd = process.cwd(); | ||
if (!base) { | ||
base = cwd; | ||
} | ||
const path = require('path'); | ||
const { read, clobber } = require('internal/modules/package_json_reader'); | ||
const cwdPackage = read(path.join(cwd, 'package.json')); | ||
const entryPackage = read(path.join(base, 'package.json')); | ||
if ( | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. This seems like a reasonable tradeoff for now. |
||
} | ||
clobber(path.join(base, 'package.json'), implicitPackageJSONPath); | ||
} | ||
|
||
// TODO(joyeecheung): most of these should be deprecated and removed, | ||
// except some that we need to be able to mutate during run time. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,4 +38,14 @@ function read(jsonPath) { | |
return result; | ||
} | ||
|
||
module.exports = { read }; | ||
/** | ||
* | ||
* @param {string} jsonPath | ||
* @param {string} srcPath | ||
*/ | ||
bmeck marked this conversation as resolved.
Show resolved
Hide resolved
|
||
function clobber(jsonPath, srcPath) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about just making this There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Yeah! (eg There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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. |
||
const value = cache.has(srcPath) ? cache.get(srcPath) : read(srcPath); | ||
bmeck marked this conversation as resolved.
Show resolved
Hide resolved
|
||
cache.set(jsonPath, value); | ||
} | ||
|
||
module.exports = { clobber, read }; |
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 likemodule-package.test
we could go forpackage-file
, does that seem fine?Uh oh!
There was an error while loading. Please reload this page.
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.node/lib/internal/errors.js
Line 1183 in 3ef9562
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 thepackage.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.