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

feat: upgrade to yarn2 and improve compilation step #491

Closed
wants to merge 40 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
56d536e
feat: upgrade to yarn2 and improve compilation step
amcgee Dec 3, 2020
abd7d98
chore: cleanup
amcgee Dec 3, 2020
6da2e56
ci: update workflow for yarn2
amcgee Dec 3, 2020
877d1aa
chore: check in yarn cache for zero-install
amcgee Dec 4, 2020
a35777e
ci: re-add node_modules and yarn caching in workflow
amcgee Dec 4, 2020
0928ad0
chore: add pnp manifest
amcgee Dec 4, 2020
f85d132
chore: patch @dhis2/cli-style and update locale chunk naming
amcgee Dec 4, 2020
c729e7d
fix: add missing devDeps for adapter tests
amcgee Dec 4, 2020
1a3d21f
fix: add missing dev dependencies, fix lint step
amcgee Dec 4, 2020
c986d2b
feat: add custom shell and adapter overrides to platform scripts
amcgee Dec 4, 2020
552da5e
ci: fix workflow i18n generation
amcgee Dec 4, 2020
b2247ee
style: fix lint errors
amcgee Dec 4, 2020
ba63b92
ci: specify package and binary for dlx
amcgee Dec 4, 2020
fa1219c
chore: add vscode editor setting to ignore .yarn cache files in searches
amcgee Dec 5, 2020
9fc041c
ci: pass --package option in correct position
amcgee Dec 5, 2020
deba4e0
fix: bundle shell files in cli-app-scripts package rather than includ…
amcgee Dec 5, 2020
9e5fdf1
chore: add missing files
amcgee Dec 5, 2020
4fb6c20
fix: update resolutions, fix eslint (temporary), patch react-dev-util…
amcgee Dec 5, 2020
2d11688
fix: build shell before building adapter
amcgee Dec 5, 2020
39bdcf9
fix: build cli before using cli
amcgee Dec 5, 2020
c93a27c
chore: remove yarn cache for now to simplify PR diff
amcgee Dec 5, 2020
43d9465
chore: noop change yarn.lock to force-refresh the ci cache
amcgee Dec 5, 2020
43eb62d
ci: mutable cache since we no longer commit it
amcgee Dec 5, 2020
94396d5
chore: regenerate yarn.lock
amcgee Dec 5, 2020
7dcdc99
ci: also cache .pnp.js
amcgee Dec 5, 2020
c29b198
ci: require build before lint and test
amcgee Dec 5, 2020
39467be
ci: build example separately, also store cli assets with build artifact
amcgee Dec 5, 2020
2a09cc8
ci: require example to build before publishing
amcgee Dec 5, 2020
9389e96
chore: only generate i18n for adapter
amcgee Dec 5, 2020
7925b04
style: format workflow file
amcgee Dec 5, 2020
14a2130
chore: make root scripts nicer, override cli-utils glob dep
amcgee Dec 5, 2020
d9b5f1c
chore: remove cruft and add another missing cli-utils dep
amcgee Dec 5, 2020
8bbd014
chore: re-add requires eslint config for example
amcgee Dec 5, 2020
bd77a5c
chore: add more missing cli-util packages
amcgee Dec 5, 2020
c7e10c2
chore: bundle yarn2 with shell, force yarn script resolution
amcgee Dec 9, 2020
d0e1611
chore: add app package validation and auto-fixing option
amcgee Dec 9, 2020
7964595
style: format
amcgee Dec 9, 2020
349fd1e
fix: more efficient dependency fixing, proper custom shell behavior
amcgee Dec 9, 2020
ce64a61
chore: remove unused variable
amcgee Dec 9, 2020
ed84ead
fix: add inline sourcemaps
amcgee Dec 9, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 62 additions & 14 deletions .github/workflows/dhis2-verify-lib.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: 'dhis2: verify (lib)'

on:
push:
branches:
on: push

env:
GIT_AUTHOR_NAME: '@dhis2-bot'
Expand All @@ -27,12 +25,15 @@ jobs:
- uses: actions/cache@v2
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: '**/node_modules'
path: |
.yarn/**
**/node_modules
.pnp.js
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}

- name: Install
if: steps.yarn-cache.outputs.cache-hit != 'true'
run: yarn install --frozen-lockfile
run: yarn install --immutable

build:
runs-on: ubuntu-latest
Expand All @@ -47,7 +48,10 @@ jobs:
- uses: actions/cache@v2
id: yarn-cache
with:
path: '**/node_modules'
path: |
.yarn/**
**/node_modules
.pnp.js
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}

- name: Build
Expand All @@ -58,12 +62,13 @@ jobs:
name: lib-build
path: |
**/build
cli/assets
!**/node_modules
retention-days: 1

lint:
runs-on: ubuntu-latest
needs: [install]
needs: [install, build]
if: "!contains(github.event.head_commit.message, '[skip ci]')"
steps:
- uses: actions/checkout@v2
Expand All @@ -74,18 +79,25 @@ jobs:
- uses: actions/cache@v2
id: yarn-cache
with:
path: '**/node_modules'
path: |
.yarn/**
**/node_modules
.pnp.js
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}

- name: Build
run: yarn build
- uses: actions/download-artifact@v2
with:
name: lib-build

- name: Generate i18n
run: yarn i18n:generate

- name: Lint
run: yarn lint

test:
runs-on: ubuntu-latest
needs: [install]
needs: [install, build]
if: "!contains(github.event.head_commit.message, '[skip ci]')"
steps:
- uses: actions/checkout@v2
Expand All @@ -96,15 +108,51 @@ jobs:
- uses: actions/cache@v2
id: yarn-cache
with:
path: '**/node_modules'
path: |
.yarn/**
**/node_modules
.pnp.js
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}

- uses: actions/download-artifact@v2
with:
name: lib-build

- name: Generate i18n
run: yarn i18n:generate

- name: Test
run: yarn test

build-example:
runs-on: ubuntu-latest
needs: [install, build]
if: "!contains(github.event.head_commit.message, '[skip ci]')"
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12.x

- uses: actions/cache@v2
id: yarn-cache
with:
path: |
.yarn/**
**/node_modules
.pnp.js
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}

- uses: actions/download-artifact@v2
with:
name: lib-build

- name: Build example
run: yarn build:example

publish:
runs-on: ubuntu-latest
needs: [build, lint, test]
needs: [build, lint, test, build-example]
if: "!contains(github.event.head_commit.message, '[skip ci]')"
steps:
- uses: actions/checkout@v2
Expand All @@ -119,4 +167,4 @@ jobs:
name: lib-build

- name: Publish to NPM
run: npx @dhis2/cli-utils release --publish npm
run: yarn dlx --package @dhis2/cli-utils d2-utils release --publish npm
15 changes: 12 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

# dependencies
node_modules
.pnp
.pnp.js

# testing
**/coverage
Expand All @@ -29,4 +27,15 @@ cli/assets

npm-debug.log*
yarn-debug.log*
yarn-error.log*
yarn-error.log*

.eslintcache

# yarn2
.yarn/*
!.yarn/patches
!.yarn/releases
!.yarn/plugins
!.yarn/sdks
!.yarn/versions
.pnp.*
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"search.exclude": {
"**/.yarn": true,
}
}
77 changes: 77 additions & 0 deletions .yarn/patches/@dhis2-cli-style.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
diff --git a/src/utils/run.js b/src/utils/run.js
index c1347e03ddc5809405b2734c373438e08d89539a..5960280186fa7ba1edcf107f6ad916cf0eaa43c7 100644
--- a/src/utils/run.js
+++ b/src/utils/run.js
@@ -1,7 +1,6 @@
const path = require('path')
+const fs = require('fs')
const spawn = require('cross-spawn')
-const findup = require('find-up')
-const { PACKAGE_ROOT } = require('./paths.js')

exports.spawn = (cmd, args, opts) =>
spawn.sync(cmd, args, {
@@ -19,17 +18,12 @@ exports.run = (cmd, { args, opts }, callback) => {
)
}

-exports.bin = (cmd, { args, opts }, callback) => {
- const nodemodules = findup.sync('node_modules', {
- cwd: PACKAGE_ROOT,
- type: 'directory',
- allowSymlinks: true,
- })
-
- const binCmd = path.join(nodemodules, '.bin', cmd)
+exports.bin = (packageName, { bin, args, opts }, callback) => {
+ const binFile = findBin(packageName, bin)
+ const yarnArgs = ['node', binFile, ...args]

return handleRun(
- spawn.sync(binCmd, args, {
+ spawn.sync('yarn', yarnArgs, {
stdio: 'inherit',
...opts,
}),
@@ -37,6 +31,41 @@ exports.bin = (cmd, { args, opts }, callback) => {
)
}

+function findBin(packageName, bin) {
+ let pkg
+ try {
+ pkg = require(`${packageName}/package.json`)
+ } catch (e) {
+ throw new Error(`Cannot resolve package ${packageName}`)
+ }
+ const pkgRoot = path.dirname(require.resolve(`${packageName}/package.json`))
+
+ const binName = bin || packageName
+ let binFile
+ if (typeof pkg.bin === 'string') {
+ if (binName === packageName) {
+ binFile = pkg.bin
+ }
+ } else {
+ binFile = pkg.bin[binName]
+ }
+
+ if (!binFile) {
+ throw new Error(
+ `No bin entry for ${binName} found in package ${packageName}`
+ )
+ }
+
+ binFile = path.join(pkgRoot, binFile)
+ if (!fs.existsSync(binFile)) {
+ throw new Error(
+ `Bin entry ${binName} in package ${packageName} points to a file which does not exist (${binFile})`
+ )
+ }
+
+ return binFile
+}
+
function handleRun(result, callback) {
if (result.error) {
throw result.error
55 changes: 55 additions & 0 deletions .yarn/releases/yarn-2.4.0.cjs

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
yarnPath: .yarn/releases/yarn-2.4.0.cjs
packageExtensions:
'@dhis2/cli-utils@*':
dependencies:
'@semantic-release/error': '*'
aggregate-error: '*'
glob: '*'
12 changes: 9 additions & 3 deletions adapter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,19 @@
"build"
],
"dependencies": {
"moment": "^2.24.0"
"moment": "^2.24.0",
"prop-types": "^15.7.2"
},
"devDependencies": {
"@dhis2/app-runtime": "^2.6.1",
"@dhis2/cli-app-scripts": "5.5.0",
"@dhis2/d2-i18n": "^1.0.6",
"@dhis2/ui": "^5.7.8",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.5"
"enzyme-adapter-react-16": "^1.15.5",
"react": "^16",
"react-dom": "^16",
"styled-jsx": "^3.3.2"
},
"scripts": {
"build": "d2-app-scripts build",
Expand All @@ -34,7 +41,6 @@
"@dhis2/ui": "^5",
"classnames": "^2",
"moment": "^2",
"prop-types": "^15",
"react": "^16.8",
"react-dom": "^16.8",
"styled-jsx": "^3"
Expand Down
4 changes: 3 additions & 1 deletion adapter/src/utils/useLocale.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ const simplifyLocale = locale => {

const setGlobalLocale = locale => {
if (locale !== 'en' && locale !== 'en-us') {
import(`moment/locale/${locale}`).catch(() => {
import(
/* webpackChunkName: 'moment-[request]' */ `moment/locale/${locale}`
).catch(() => {
/* ignore */
})
}
Expand Down
1 change: 1 addition & 0 deletions cli/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
assets
1 change: 1 addition & 0 deletions cli/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
assets/shell.js
2 changes: 1 addition & 1 deletion cli/config/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const visualize = require('rollup-plugin-visualizer')
const { reporter, chalk } = require('@dhis2/cli-helpers-engine')
const extensions = ['.js', '.jsx', '.ts', '.tsx']

const standardLibs = require('@dhis2/app-shell/package.json').dependencies
const standardLibs = require('../assets/shell/package.json').dependencies

// Exclude local app-shell dependencies
Object.entries(standardLibs).forEach(([dep, version]) => {
Expand Down
8 changes: 6 additions & 2 deletions cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"files": [
"bin",
"config",
"src"
"src",
"assets"
],
"dependencies": {
"@babel/core": "^7.6.2",
Expand All @@ -32,7 +33,6 @@
"@babel/preset-env": "^7.9.0",
"@babel/preset-react": "^7.0.0",
"@babel/preset-typescript": "^7.6.0",
"@dhis2/app-shell": "5.5.0",
"@dhis2/cli-helpers-engine": "^1.5.0",
"archiver": "^3.1.1",
"axios": "^0.20.0",
Expand Down Expand Up @@ -65,5 +65,9 @@
},
"bin": {
"d2-app-scripts": "./bin/d2-app-scripts"
},
"scripts": {
"build": "yarn node ./scripts/bundle-shell.js ../shell ./assets/shell",
"prepack": "yarn build"
}
}
36 changes: 36 additions & 0 deletions cli/scripts/bundle-shell.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* This utility node script is used to copy the current shell into this package for bundled publication
*/

const fs = require('fs-extra')
const { reporter } = require('@dhis2/cli-helpers-engine')

const bundleShell = (shellDir, shellAssetPath) => {
fs.removeSync(shellAssetPath)

fs.copySync(shellDir, shellAssetPath, {
filter: src => !src.match(`^${shellDir}/(node_modules|build)($|/.*)`),
})
}

const shellDir = process.argv[2]
const shellAssetPath = process.argv[3]

if (!shellDir || !shellAssetPath) {
reporter.error(
`Usage: yarn node ${process.argv[1]} <shellDir> <shellAssetPath>`
)
process.exit(1)
}

if (!fs.existsSync(shellDir) || !fs.statSync(shellDir).isDirectory()) {
reporter.error(`Path ${shellDir} does not exist or is not a directory`)
process.exit(2)
}

reporter.info('Bundling shell asset...')

bundleShell(shellDir, shellAssetPath)

reporter.info('Done!')
process.exit(0)
Loading