-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Introducing y-npm
(aka: Why NPM?)
#162
Conversation
1ff8d6a
to
05f6167
Compare
y-npm
(aka: Why NPM?)y-npm
(aka: Why NPM?)
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.
Didn't go through everything yet, see my note about bundling...
bundle-beta.sh
Outdated
${Y_NPM} publish ${tarball} | ||
done | ||
|
||
echo "Installing y-npm" # using my-npm! |
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.
"my-npm" => "y-npm"
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.
🤦🏻♂️
bundle-beta.sh
Outdated
# Symlink 'bin' to the root | ||
echo "Installing cdk-beta-npm" | ||
mkdir -p bin | ||
cat > bin/cdk-beta-npm <<-'HERE' |
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.
Let's get rid of cdk-beta-npm
altogether!
- I think the name is wrong in 4 different ways (too long, confusing, ugly, non-ergonomic).
- We are going to have
y-mvn
andy-nuget
and eventually we'll publishy-repo
as a separate project and can point people to it's docs in case they have any questions or issues. Adding another abstraction layer on top of it will make it hard for people to understand what's going on.
How do we get rid of it? Include most of the bundling logic into y-npm
. Think about other users of y-npm - they will effectively have to re-write the code in bundle-beta.sh
.
Here's a proposal for an API:
$ y-npm y-stage <tarballs>
bin/y-npm
node_modules/y-npm
node_modules/...
y/npm/<verdaccio-tree>
This will allow you to define the default for behavior in case Y_NPM_REPO
is not defined to auto-locate it's repo y/npm/
based on where the y-npm module is installed path.join(__dirname, '../../y.npm')
.
This will also apply exactly in the same way to y-mvn
.
Eventually, all one will need to do is zip the staging directory and be happy!
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.
It took me reading your suggestion thrice, but now that I understand it, I like it 👍
I'll use y/npm
repository resolution akin to what node
does:
${Y_NPM_REPOSITORY}
${cwd}/y/npm
- Walk up the tree from
${cwd}
until:- A
y/npm
directory is found - The root of the filesystem is reached
- A
- Walk up the tree from
path.join(require.resolve('y-npm/package.json'), '..', '..')
until:- A
y/npm
directory is found - The root of the filesystem is reached
- A
- Bail out in error.
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.
sounds great!
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.
Now done 👌🏻
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.
You should write a couple of tests to get at least minimal coverage of the behavior. I would write a few bash scripts that exercise the tool in a few paths.
I am still not in ❤️ with our eventual setup story but we can punt that for a subsequent iteration.
CHANGELOG.md
Outdated
|
||
* Stopped bundling all dependencies in the release ZIP ([@RomainMuller] in [#161] and [awslabs/jsii#43]) | ||
* Replaced `cdk-beta-npm` with more generic `y-npm` tool ([@RomainMuller] in [#162]) | ||
* Improved speed of `pack.sh` |
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.
Not needed in changelog
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.
All of them? Or some of them?
bundle-beta.sh
Outdated
# aws-cdk-${version}.zip | ||
# ├─ bin | ||
# ├─ docs | ||
# ├─ repo |
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 will change this to y/mvn
shortly
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 already changed y/npm
:)
packages/aws-cdk/lib/init.ts
Outdated
if (await execCdkBetaNpm('install') !== 0) { | ||
throw new Error('cdk-beta-npm install failed!'); | ||
const cdkHome = process.env.CDK_HOME ? path.resolve(process.env.CDK_HOME) : path.join(os.homedir(), '.cdk'); | ||
const cdkBetaNpm = path.join(cdkHome, 'bin', 'y-npm'); |
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.
rename variable
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! Yes.
tools/y-npm/README.md
Outdated
``` | ||
* For a package from your `npm` registry of choice: | ||
```shell | ||
TGZ=npm pack package[@version] # Download the package locally |
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.
missing $()
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.
🤦🏻♂️
tools/y-npm/README.md
Outdated
```shell | ||
TGZ=npm pack package[@version] # Download the package locally | ||
y-npm publish ${TGZ} # Publish the downloaded package | ||
rm ${TGZ} # Clean-up after yourself |
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.
😄
tools/y-npm/bin/y-npm.ts
Outdated
const storage = await determineStorageDirectory(); | ||
if (argv.length === 1) { | ||
switch (argv[0]) { | ||
case 'my-packages': |
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.
shouldn't that be y-packages
or better: y-ls
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.
Like y-ls
.
import { debug } from './logging'; | ||
|
||
/** The parent directory of this module's location */ | ||
const installRoot = path.resolve(path.join(__dirname, '..', '..')); |
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.
why not just __dirname
?
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 could start by testing two directories that I know upfront will not contain a y/npm
directory, but I chose to save the effort.
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.
Fair enough
return await callback(file); | ||
} finally { | ||
await fs.remove(file); | ||
await fs.remove(dir); |
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.
cant you rm -fr the dir?
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 couldn't find a fs
API that would achieve this. I can implement a short recursive remove if you want?
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.
fs-extra
has one and it's a good package to depend on
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.
Replacing with fs.emptyDir(dir)
then fs.remove(dir)
. Or is there a call that does both?
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 believe fs.remove
is idempotent
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.
remove should be sufficient
I've changed the set-up process a bit -- the Updated the PR description accordingly. |
Pre-installing I think the instructions of "unzip and run |
bundle-beta.sh
Outdated
@@ -37,8 +37,8 @@ for tarball in $(find ${root}/.local-npm -iname '*.tgz') $(find ${root}/pack -in | |||
${Y_NPM} publish ${tarball} | |||
done | |||
|
|||
echo "Installing y-npm" # using y-npm! | |||
${Y_NPM} install --global-style --no-save y-npm | |||
echo "Installing y-npm, aws-cdk and aws-cdk-docs" # using y-npm! |
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 one step to far... We are losing the idiomatic experience y-npm
bought us and won't work on Windows (#138).
tools/y-npm/test/test.sh
Outdated
} | ||
trap cleanup EXIT | ||
|
||
# Now we'll create a hierarchy: |
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.
Can you add a few words on the motivation for this directory structure?
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.
The comments on the structure itself attempt to explain the motivation. Can you elaborate on what is not clear enough? I've updated this a little in the upcoming revision.
tools/y-npm/test/test.sh
Outdated
if [ "${expected}" == "${actual}" ]; then | ||
echo "✅ ${title}" | ||
else | ||
echo "❌ ${title}" |
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've used bats in the past and loved it.
tools/y-npm/bin/y-npm.ts
Outdated
case 'my-packages': | ||
debug(`Invoking special command: my-packages`); | ||
case 'y-ls': | ||
debug(`Invoking special command: y-ls`); |
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.
instead of "special" maybe "invoking y-npm command: y-ls" (gives people a reference to where this is coming from)
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.
Yah!
return await callback(file); | ||
} finally { | ||
await fs.remove(file); | ||
await fs.remove(dir); |
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.
remove should be sufficient
A drop-in replacement for the `npm` command that uses a local repository as a source for packages, and falls back to the standard `npm` registry for packages that are not locally available. This can be used to make private packages available to consumers without the need to set up a full blown repository and managing user authentication and authorization; and also to overlay customized versions of third party packages in a simple way. The `y-npm` command has an additional sub-command `y-npm y-ls` that will output the name and version of all packages that are locally available. This commit also replaces cdk-beta-npm in favor of using y-npm. Also, the release .zip file no longer includes a full installation of the cdk, instead only makes y-npm, so people can use y-npm instead of npm and work as they normally would besides that (this reduces the file size of the release zip by about 50%).
a1e780d
to
0eba137
Compare
A drop-in replacement for the
npm
command that uses a local repository as a source for packages, and falls back to the standardnpm
registry for packages that are not locally available.This can be used to make private packages available to consumers without the need to set up a full blown repository and managing user authentication and authorization; and also to overlay customized versions of third party packages in a simple way.
The
y-npm
command has an additional sub-commandy-npm y-ls
that will output the name and version of all packages that are locally available.This commit also replaces
cdk-beta-npm
in favor of usingy-npm
. Also, the release.zip
file no longer includes a full installation of thecdk
, instead only makesy-npm
, so people can usey-npm
instead ofnpm
and work as they normally would besides that (this reduces the file size of the release zip by about 50%).