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

build: introduce a 'prepare' script in embark's package.json #1128

Merged
merged 1 commit into from
Dec 3, 2018

Conversation

michaelsbradleyjr
Copy link
Contributor

@michaelsbradleyjr michaelsbradleyjr commented Nov 25, 2018

build: introduce a prepare script in embark's package.json

TL;DR

These changes affect workflow with yarn. To prevent embark's prepare script from running undesirably:

  • If node_modules is in place and you're reinstalling after switching branches:

yarn run install_all

  • If node_modules is missing (fresh clone or deleted):

EMBARK_NO_PREPARE=t yarn install && yarn run install_all

It's not recommended to set EMBARK_NO_PREPARE in your environment (e.g. in .bashrc) since that would interfere with embark's release script if/when you run it.


1. Specify embark's build-related steps in the prepare script of package.json.

When embark is installed directly from GitHub the prepare script results in a "pre install" phase (handled automatically by npm/yarn) that fetches devDependencies, builds embark (including embark-ui), packs a tarball with the same steps (minus testing and tree-checking) as would happen during an embark release, and finally does a production install from that tarball.

Important point: installs from GitHub must be performed with yarn; they're no longer possible with npm since during the "pre install" phase npm will honor embark's .npmrc and "engines" settings.

The following will work correctly after this commit is merged:

yarn [global] add git+https://github.com/embark-framework/embark.git

Use of "hosted git" shortcuts (e.g. embark-framework/embark#bracnh) won't work correctly because yarn doesn't fully support them. See: yarnpkg/yarn#5235.

It's important to use git+https urls. Following a succesful install with git+https it is possible to use a "hosted git" shortcut or https url, but that's owing to a subtle and unreliable interaction between yarn's cache and yarn's logic for installing from a url/shortcut.

2. Adjust the npm configs (.npmrc) for embark/-ui so that yarn run [cmd] [--opt] can be used in place of npm run [cmd] -- [--opt].

Either way is okay for running scripts, they're equivalent, but note the requirement to use -- before specifying command options with npm run.

3. Introduce yarn configs (.yarnrc) for embark/-ui and include the check-files directive.

H/t to @alaibe for the recommendation.

4. Ignore embark's dist/typings and scripts directories when packing a tarball.

5. Refactor embark/-ui's npm-scripts in relation to the prepare script, and make other small improvements.

Notably, if the environment variable EMBARK_NO_PREPARE is truthy (from JS perspective) then embark's prepare script will exit early. This prevents install_all and prepare from getting stuck in a loop (install:core uses cross-env to set EMBARK_NO_PREPARE) and provides a mechanism for users to skip the prepare script when doing a fresh install:

EMBARK_NO_PREPARE=t yarn install

6. Give .js extensions to node scripts in embark's scripts/, remove the shebang lines, and have npm-scripts explicitly invoke them with node.

This arrangement works for all platforms: Linux, macOS, and Windows.

7. Adjust travis and appveyor configs.

Since at present there aren't any tests or other CI steps that make use of embark-ui's production build, set EMBARK_NO_PREPARE in the CI environments and invoke build:node directly.

Check the working tree after yarn install for embark/-ui. This detects situations where changes should have been committed to yarn.lock but were not. Check the working tree again at the end to detect situations where ignore files should have been adjusted but were not. Both checks could also detect other surprising behavior that needs to be investigated. Any time the working tree is not clean (there are untracked files or changes) CI will fail.

Drop CI runs for node 8.11.3 because that version ships with an older npm that results in unstaged changes to the test apps' package-lock.json files, causing the working tree check to fail at the end of the CI run. A simple workaround isn't apparent, but the matter can be revisited.

8. Refactor embark's release script in light of the prepare script.

Notably, do the push step only after npm publish completes successfully. This allows embark's prepare and prepublishOnly scripts to detect problems before a commit and tag are pushed to GitHub, avoiding a need to rebase/revert the remote release branch; the local branch will still need to have a commit dropped and tag deleted before rerunning the release script.

Prompt the user if the release script is not being run in --dry-run mode.

Provide additional visual indicators of --dry-run mode.

Force the user to supply --repo-branch [branch] if the intention is to release from a branch other than master.

@michaelsbradleyjr michaelsbradleyjr requested a review from a team November 25, 2018 17:38
@michaelsbradleyjr
Copy link
Contributor Author

scripts/release.js has been manually tested very carefully to check that all steps behave as intended in both dry and non-dry runs for every success and error condition.

Copy link
Contributor

@0x-r4bbit 0x-r4bbit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some minor comments there.

I think it'd be a good time to introduce some "developer" docs for us where we can read about how to get Embark up and running an make releases etc.

throw new Error();
}

logSuccess(`Current branch and relase branch are the same.`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

relase => release

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, fixed! (and rebased with master)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll squash the post-feedback commits when it's time to merge into master.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

`npm publish`,
leftPad1Maybe(`${distTag ? `--tag ${distTag}` : ''}`),
leftPad1Maybe(`${dryRun ? '--dry-run' : ''}`)
].join('');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we wanna join with a space here? Otherwise we'd end up with npm publish--tag foo--dry-run no?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah nevermind, there's a leftPad1Maybe. Still, wouldn't it be simpler to remove that and just join with ' ' instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could, but it would lead to extra spaces in the command string when distTag or dryRun is empty — not the end of the world but I'd prefer to not have extraneous spaces.

The idea with leftPad1/Maybe was to avoid a situation where someone in the future working on the script removes a space from a string because it looks like it was a typo and then, because testing the script is mostly a manual process, the mistake isn't realized until later. A function call is less likely to be accidentally removed, I think.

@@ -9,10 +9,12 @@ CONTRIBUTING.md
appveyor.yml
babel.config.js
dist/test
dist/typings
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we not publishing the types?
If we want to produce embark as a lib, the types are helpful.

Copy link
Contributor Author

@michaelsbradleyjr michaelsbradleyjr Nov 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can. At present, the typings scrips are being compiled into .js and effectively erased. We could:

  1. Have babel ignore that directory in which case it will copy the .ts file/s without transpiling them.
  2. Or continue excluding that directory in .npmignore but whitelist src/typcings/.

Preference?

I think we'd also need a "types" property in package.json. See: https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html

The "types" property is supposed to point to a "bundled declaration file". What's the right way to set that up?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a good question, usually TS generate those but I am not sure it is possible with babel, something to investigate.

I would say ignore my comments until we found a way to generate .d.ts file

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an option in ts config:
"declaration": true, but because we don't emit the files this is not possible.

Something to investigate but unsure would be https://www.npmjs.com/package/dts-bundle

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's possible to emit only the bundled declaration. I can investigate, but I think making that change to the build should land in another PR.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably a good idea to tackle in a new PR, though let's not forget about it :)

@michaelsbradleyjr michaelsbradleyjr force-pushed the build/prepare-script branch 2 times, most recently from 6862f97 to d7e48a4 Compare November 26, 2018 18:54
@michaelsbradleyjr michaelsbradleyjr force-pushed the build/prepare-script branch 2 times, most recently from 4afa086 to 38f31e0 Compare November 28, 2018 23:33
@michaelsbradleyjr
Copy link
Contributor Author

michaelsbradleyjr commented Nov 29, 2018

Several changes have been made in the latest WIP commit to deal with package resolution problems. I think it's probably okay that they go in this PR; this branch certainly provided a good context for testing their effects when embark is installed from GitHub with yarn, and when running embark in a development setup.

If @embark-framework/core-devs can take another look and it's judged okay, I'll squash into one commit and remove the changes needed label.

@@ -93,8 +93,7 @@ function listenTo(options, callback) {
return callback(null, data);
}
promise.cb(payload, data, result);
})
.catch(callback);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After making all of the web3 beta.34 modules direct dependencies of embark, the object returned by subscribe(...).on(...) doesn't have a .catch method. With the invocation removed, everything seems to be working okay in embark_demo.

@michaelsbradleyjr michaelsbradleyjr force-pushed the build/prepare-script branch 2 times, most recently from e7b72d8 to ca55834 Compare December 1, 2018 22:24
@michaelsbradleyjr
Copy link
Contributor Author

Module resolution commits were removed and a new PR was created for those: #1152

**TL;DR**

These changes affect workflow with yarn. To prevent embark's `prepare` script
from running undesirably:

- If node_modules is in place and you're reinstalling after switching branches:

```
yarn run install_all
```

- If node_modules is missing (fresh clone or deleted):

```
EMBARK_NO_PREPARE=t yarn install && yarn run install_all
```

It's not recommended to set `EMBARK_NO_PREPARE` in your environment (e.g. in
`.bashrc`) since that would interfere with embark's `release` script if/when
you run it.

-----------------

**1.** Specify embark's build-related steps in the `prepare` script of
  package.json.

When embark is installed directly from GitHub the `prepare` script results in a
"pre install" phase (handled automatically by npm/yarn) that fetches
devDependencies, builds embark (including embark-ui), packs a tarball with the
same steps (minus testing and tree-checking) as would happen during an embark
release, and finally does a production install from that tarball.

Important point: installs from GitHub must be performed with yarn; they're no
longer possible with npm since during the "pre install" phase npm will honor
embark's `.npmrc` and `"engines"` settings.

The following will work correctly after this commit is merged:

```
yarn [global] add git+https://github.com/embark-framework/embark.git
```

Use of "hosted git" shortcuts (e.g. `embark-framework/embark#bracnh`) won't
work correctly because yarn doesn't fully support them. See:
yarnpkg/yarn#5235.

It's important to use `git+https` urls. Following a succesful install with
`git+https` it is possible to use a "hosted git" shortcut or `https` url, but
that's owing to a subtle and unreliable interaction between yarn's cache and
yarn's logic for installing from a url/shortcut.

**2.** Adjust the npm configs (`.npmrc`) for embark/-ui so that `yarn run [cmd]
  [--opt]` can be used in place of `npm run [cmd] -- [--opt]`.

Either way is okay for running scripts, they're equivalent, but note the
requirement to use `--` before specifying command options with `npm run`.

**3.** Introduce yarn configs (`.yarnrc`) for embark/-ui and include the
  `check-files` directive.

H/t to @alaibe for the recommendation.

**4.** Ignore embark's `dist/typings` and `scripts` directories when packing a
  tarball.

**5.** Refactor embark/-ui's npm-scripts in relation to the `prepare` script,
  and make other small improvements.

Notably, if the environment variable `EMBARK_NO_PREPARE` is truthy (from JS
perspective) then embark's `prepare` script will exit early. This prevents
`install_all` and `prepare` from getting stuck in a loop (`install:core` uses
cross-env to set `EMBARK_NO_PREPARE`) and provides a mechanism for users to
skip the `prepare` script when doing a fresh install:

```
EMBARK_NO_PREPARE=t yarn install
```

**6.** Give `.js` extensions to node scripts in embark's `scripts/`, remove the
  shebang lines, and have npm-scripts explicitly invoke them with node.

This arrangement works for all platforms: Linux, macOS, and Windows.

**7.** Adjust travis and appveyor configs.

Since at present there aren't any tests or other CI steps that make use of
embark-ui's production build, set `EMBARK_NO_PREPARE` in the CI environments
and invoke `build:node` directly.

Check the working tree after `yarn install` for embark/-ui. This detects
situations where changes should have been committed to `yarn.lock` but were
not. Check the working tree again at the end to detect situations where ignore
files should have been adjusted but were not. Both checks could also detect
other surprising behavior that needs to be investigated. Any time the working
tree is not clean (there are untracked files or changes) CI will fail.

Drop CI runs for node 8.11.3 because that version ships with an older npm that
results in unstaged changes to the test apps' `package-lock.json` files,
causing the working tree check to fail at the end of the CI run. A simple
workaround isn't apparent, but the matter can be revisited.

**8.** Refactor embark's `release` script in light of the `prepare` script.

Notably, do the push step only after `npm publish` completes successfully. This
allows embark's `prepare` and `prepublishOnly` scripts to detect problems
before a commit and tag are pushed to GitHub, avoiding a need to rebase/revert
the remote release branch; the local branch will still need to have a commit
dropped and tag deleted before rerunning the `release` script.

Prompt the user if the `release` script is not being run in `--dry-run` mode.

Provide additional visual indicators of `--dry-run` mode.

Force the user to supply `--repo-branch [branch]` if the intention is to
release from a branch other than `master`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants