-
Notifications
You must be signed in to change notification settings - Fork 412
feat: publish netlify
package
#7293
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
Changes from 2 commits
6d757f1
a56363a
70dacdb
0bbc22d
9e5e4a1
fa878fc
01b4055
5822c84
92e0755
7b3d3d9
8c1e8bb
bc1f081
0490402
c9d4f80
7a9405d
384e146
fda2b6c
0623be6
06be0e1
548eeb9
5cdda7b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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. nit: I was going to comment that this codebase does not follow this naming convention, but I see that 🤷🏼 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. I did name |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// @ts-check | ||
import assert from 'node:assert' | ||
import { basename, dirname, resolve } from 'node:path' | ||
import { argv } from 'node:process' | ||
import { fileURLToPath } from 'node:url' | ||
import { readFile, writeFile } from 'node:fs/promises' | ||
|
||
import execa from 'execa' | ||
|
||
const packageJSON = await getPackageJSON() | ||
|
||
async function getPackageJSON() { | ||
const packageJSONPath = resolve(fileURLToPath(import.meta.url), '../../package.json') | ||
const contents = JSON.parse(await readFile(packageJSONPath, 'utf8')) | ||
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. nit: We already have a dep on There's even a util 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 use case is a bit different. We're reading I have used the |
||
|
||
return { | ||
contents, | ||
path: packageJSONPath, | ||
} | ||
} | ||
|
||
/** | ||
* @type {Record<string, function>} | ||
*/ | ||
const commands = { | ||
prepare: async () => { | ||
const newPackageJSON = { | ||
...packageJSON.contents, | ||
main: './dist/index.js', | ||
name: 'netlify', | ||
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. Now I'm wondering if we should also change the name of the binary so that 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. As far as I understand the wonky npm heuristics here:
(It's likely worth verifying these) Does this seem ok or are any of these scenarios problematic? 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. My question is whether But if |
||
} | ||
|
||
console.log(`Writing updated package.json to ${packageJSON.path}...`) | ||
await writeFile(packageJSON.path, `${JSON.stringify(newPackageJSON, null, 2)}\n`) | ||
|
||
console.log('Re-installing dependencies to update lockfile...') | ||
await execa('npm', ['install'], { | ||
cwd: dirname(packageJSON.path), | ||
}) | ||
eduardoboucas marked this conversation as resolved.
Show resolved
Hide resolved
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. Hrm, his is getting difficult to reason about... So, before this script runs in CI, we'll have run this as part of the This means we'll have mutated @ndhoule and I just recently decomplicated all of this (with many false starts due to how tangled and brittle it was), so I think it would be worth avoiding getting back into this state if we can help it. I don't have concrete suggestions that fit in a comment box, but I'm happy to pair on it if you'd like. 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. Okay, I hadn't realised that this flow had changed. My bad. In 70dacdb I have made the following changes:
Let me know if that makes sense. |
||
}, | ||
|
||
verify: async () => { | ||
const { stdout } = await execa('npx', ['-y', 'netlify', '--version']) | ||
const version = stdout.match(/netlify-cli\/(\d+\.\d+\.\d+)/) | ||
|
||
assert.equal(version, packageJSON.contents.version, 'Version installed via npx matches latest version') | ||
}, | ||
eduardoboucas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
if (typeof commands[argv[2]] === 'function') { | ||
await commands[argv[2]]() | ||
} else { | ||
console.error(`Usage: node ${basename(argv[1])} <command> (available commands: ${Object.keys(commands).join(', ')})`) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// This is an entrypoint that mirrors the interface that the `netlify` package | ||
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. thought: Should we log a warning here that the package has been renamed? 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. That feels a bit extreme? We might be logging something that is not actionable to the user, since this might be a transitive dependency. |
||
// used to have, before it was renamed to `@netlify/api`. We keep it for | ||
// backwards-compatibility. | ||
export { NetlifyAPI, methods } from '@netlify/api' |
Uh oh!
There was an error while loading. Please reload this page.