Skip to content

Commit a4f7e77

Browse files
piehsidharthachatterjee
authored andcommitted
feat(gatsby-dev-cli): add verdaccio support (gatsbyjs#11525)
* feat(gatsby-dev-cli): add verdaccio support [wip] * yuck - don't look * just to verify verdaccio * fix gitignore and add htpasswd with dummy gatsby-dev user * some logging to understand why it tries to handle all the packages * just temporarily so it hopefully at least works * moar data * don't copy all the packages right now * don't rely on package name starting with "gatsby" heuristic * tmp commit * tmp * fs change * tmp * a * updates * remove random files that shouldn't be here * tmp * revert dep changes * ignore changes to package.json created during publishing * testing of dep change in gatsby-cli is picked up by gatsby-dev-cli * let's see if gatsby-dev will handle case of no node_modules * sanity check * adjust console message * add missing devDeps * more missing devDeps * grab package.json from unpkg if package is not yet installed locally * correctly ignore package.json changes during publishing * cleaning things up * htpasswd loc * restore gatsby package.json * adjust ignore files * gatsby-dev-cli: ignore tests * remove extra ln * less console output * turns out you don't need htpasswd after all * use exact when installing local packages - timestamp is used in version * why it failed? * use yarn for publishing - see verdaccio/verdaccio#997 * v0.1.1 * add temporary .npmrc file to allow anonymous publishes * add some jsdocs * update yarn.lock * oops * debug why still can't publish anon * adjust npmrc content * doh * Revert "debug why still can't publish anon" This reverts commit fc1045a. * handle package installation of deps didn't change * skip version changes for packages in gatsby mono-repo, queue copying instead of doing it immediately * fix tests * packages stored in verdaccio storage seems to be picked up by jest and causing trouble, so let's ignore verdaccio storage directory * bye "wat", you will be missed * bail early to avoid conditional bracket hell * more bailing early * more concise * new line * use exaca to simplify running yarn * clean up www/.gitignore * handle not existing packages * remove unused (was needed for basic auth) * cleanup temp file changes when process exit in middle of publishing * ops * Apply suggestions from code review Co-Authored-By: pieh <[email protected]> * cleanup unpkg response handler * move stuff around * remove tmp comment * document traversePackageDocs fn * restrcuture files * add basic tests for traversingPackageDeps * add basic tests for generating packages to publish (based on dep graph) * fix tests on windows * handle circular dependencies when constructing list of packages to publish * remove cat ;( * restore original e2e-test script * update gitignore
1 parent 25a93de commit a4f7e77

File tree

19 files changed

+3874
-84
lines changed

19 files changed

+3874
-84
lines changed

jest.config.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ const builtTestsDirs = pkgs
1111
.filter(p => fs.existsSync(path.join(p, `src`)))
1212
.map(p => path.join(p, `__tests__`))
1313
const distDirs = pkgs.map(p => path.join(p, `dist`))
14-
const ignoreDirs = [].concat(gatsbyBuildDirs, builtTestsDirs, distDirs)
14+
const ignoreDirs = [`<rootDir>/packages/gatsby-dev-cli/verdaccio`].concat(
15+
gatsbyBuildDirs,
16+
builtTestsDirs,
17+
distDirs
18+
)
19+
1520
const coverageDirs = pkgs.map(p => path.join(p, `src/**/*.js`))
1621
const useCoverage = !!process.env.GENERATE_JEST_REPORT
1722

packages/babel-plugin-remove-graphql-queries/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"devDependencies": {
66
"@babel/cli": "^7.0.0",
77
"@babel/core": "^7.0.0",
8-
"babel-preset-gatsby-package": "^0.1.4"
8+
"babel-preset-gatsby-package": "^0.1.4",
9+
"cross-env": "^5.1.4"
910
},
1011
"license": "MIT",
1112
"main": "index.js",

packages/babel-preset-gatsby/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
"watch": "babel -w src --out-dir . --ignore **/__tests__"
2222
},
2323
"devDependencies": {
24-
"babel-preset-gatsby-package": "^0.1.4"
24+
"@babel/cli": "^7.0.0",
25+
"babel-preset-gatsby-package": "^0.1.4",
26+
"cross-env": "^5.1.4"
2527
}
2628
}

packages/gatsby-dev-cli/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@ node_modules
2828

2929
decls
3030
dist
31+
32+
# verdaccio local storage
33+
verdaccio

packages/gatsby-dev-cli/.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
src
22
flow-typed
3+
verdaccio

packages/gatsby-dev-cli/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@
1313
"@babel/runtime": "^7.0.0",
1414
"chokidar": "^1.7.0",
1515
"configstore": "^3.1.0",
16+
"execa": "^1.0.0",
1617
"fs-extra": "^4.0.1",
1718
"is-absolute": "^0.2.6",
1819
"lodash": "^4.17.10",
20+
"request": "2.88.0",
21+
"signal-exit": "^3.0.2",
22+
"verdaccio": "^3.11.1",
1923
"yargs": "^8.0.2"
2024
},
2125
"devDependencies": {
@@ -32,9 +36,9 @@
3236
"main": "index.js",
3337
"repository": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-dev-cli",
3438
"scripts": {
35-
"build": "babel src --out-dir dist",
39+
"build": "babel src --out-dir dist --ignore **/__tests__",
3640
"prepare": "cross-env NODE_ENV=production npm run build",
3741
"test": "echo \"Error: no test specified\" && exit 1",
38-
"watch": "babel -w src --out-dir dist"
42+
"watch": "babel -w src --out-dir dist --ignore **/__tests__"
3943
}
4044
}

packages/gatsby-dev-cli/src/__tests__/watch.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,21 @@ describe(`watching`, () => {
5959
expect(fs.copy).not.toHaveBeenCalled()
6060
})
6161

62-
it(`copies files on watch event`, () => {
62+
it(`it doesn't copy files before ready event`, async () => {
6363
const filePath = path.join(process.cwd(), `packages/gatsby/dist/index.js`)
6464
watch(...args)
65-
callEventCallback(`add`, filePath)
65+
await callEventCallback(`add`, filePath)
66+
67+
expect(fs.copy).toHaveBeenCalledTimes(0)
68+
})
69+
70+
it(`copies files after ready event`, async () => {
71+
const filePath = path.join(process.cwd(), `packages/gatsby/dist/index.js`)
72+
watch(...args)
73+
await callEventCallback(`add`, filePath)
74+
await callReadyCallback()
75+
76+
// console.log(`checking`)
6677

6778
expect(fs.copy).toHaveBeenCalledTimes(1)
6879
expect(fs.copy).toHaveBeenCalledWith(
@@ -72,14 +83,15 @@ describe(`watching`, () => {
7283
)
7384
})
7485

75-
it(`copies cache-dir files`, () => {
86+
it(`copies cache-dir files`, async () => {
7687
watch(...args)
7788

7889
const filePath = path.join(
7990
process.cwd(),
8091
`packages/gatsby/cache-dir/register-service-worker.js`
8192
)
82-
callEventCallback(`add`, filePath)
93+
await callEventCallback(`add`, filePath)
94+
await callReadyCallback()
8395

8496
expect(fs.copy).toHaveBeenCalledTimes(2)
8597
expect(fs.copy).toHaveBeenLastCalledWith(
@@ -122,9 +134,9 @@ describe(`watching`, () => {
122134
global.process = realProcess
123135
})
124136

125-
it(`does not exit if scanOnce is not defined`, () => {
137+
it(`does not exit if scanOnce is not defined`, async () => {
126138
watch(...args)
127-
callReadyCallback()
139+
await callReadyCallback()
128140

129141
expect(process.exit).not.toHaveBeenCalled()
130142
})

packages/gatsby-dev-cli/src/index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,14 @@ let packages = Object.keys(
7373
_.merge({}, localPkg.dependencies, localPkg.devDependencies)
7474
)
7575

76+
// get list of packages from monorepo
77+
const monoRepoPackages = fs.readdirSync(path.join(gatsbyLocation, `packages`))
78+
7679
if (argv.copyAll) {
77-
packages = fs.readdirSync(path.join(gatsbyLocation, `packages`))
80+
packages = monoRepoPackages
7881
} else {
79-
const { dependencies } = JSON.parse(
80-
fs.readFileSync(path.join(gatsbyLocation, `packages/gatsby/package.json`))
81-
)
82-
packages = packages
83-
.concat(Object.keys(dependencies))
84-
.filter(p => p.startsWith(`gatsby`))
82+
// intersect dependencies with monoRepoPackags to get list of packages to watch
83+
packages = _.intersection(monoRepoPackages, packages)
8584
}
8685

8786
if (!argv.packages && _.isEmpty(packages)) {
@@ -104,4 +103,5 @@ gatsby-dev will pick them up.
104103
watch(gatsbyLocation, argv.packages || packages, {
105104
quiet: argv.quiet,
106105
scanOnce: argv.scanOnce,
106+
monoRepoPackages,
107107
})
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const signalExit = require(`signal-exit`)
2+
3+
const cleanupTasks = new Set()
4+
5+
exports.registerCleanupTask = taskFn => {
6+
cleanupTasks.add(taskFn)
7+
return () => {
8+
const result = taskFn()
9+
cleanupTasks.delete(taskFn)
10+
return result
11+
}
12+
}
13+
14+
signalExit(() => {
15+
if (cleanupTasks.size) {
16+
console.log(`Process exitted in middle of publishing - cleaning up`)
17+
cleanupTasks.forEach(taskFn => taskFn())
18+
}
19+
})

0 commit comments

Comments
 (0)