Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cd24d34

Browse files
refactor(gatsby): Extract waitUntilAllJobsComplete out of buil… (gatsbyjs#22059)
1 parent f71fea1 commit cd24d34

File tree

3 files changed

+26
-42
lines changed

3 files changed

+26
-42
lines changed

packages/gatsby/src/commands/build.js

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,18 @@ const { initTracer, stopTracer } = require(`../utils/tracer`)
1212
const db = require(`../db`)
1313
const signalExit = require(`signal-exit`)
1414
const telemetry = require(`gatsby-telemetry`)
15-
const { store, emitter, readState } = require(`../redux`)
15+
const { store, readState } = require(`../redux`)
1616
const queryUtil = require(`../query`)
1717
import * as appDataUtil from "../utils/app-data"
1818
import * as WorkerPool from "../utils/worker/pool"
1919
const { structureWebpackErrors } = require(`../utils/webpack-error-utils`)
20-
const {
21-
waitUntilAllJobsComplete: waitUntilAllJobsV2Complete,
22-
} = require(`../utils/jobs-manager`)
2320
import {
2421
userPassesFeedbackRequestHeuristic,
2522
showFeedbackRequest,
2623
} from "../utils/feedback"
2724
const buildUtils = require(`../commands/build-utils`)
2825
const { boundActionCreators } = require(`../redux/actions`)
26+
import { waitUntilAllJobsComplete } from "../utils/commands/jobs-manager"
2927

3028
let cachedPageData
3129
let cachedWebpackCompilationHash
@@ -45,24 +43,6 @@ type BuildArgs = {
4543
openTracingConfigFile: string,
4644
}
4745

48-
const waitUntilAllJobsComplete = () => {
49-
const jobsV1Promise = new Promise(resolve => {
50-
const onEndJob = () => {
51-
if (store.getState().jobs.active.length === 0) {
52-
resolve()
53-
emitter.off(`END_JOB`, onEndJob)
54-
}
55-
}
56-
emitter.on(`END_JOB`, onEndJob)
57-
onEndJob()
58-
})
59-
60-
return Promise.all([
61-
jobsV1Promise,
62-
waitUntilAllJobsV2Complete(),
63-
]).then(() => {})
64-
}
65-
6646
module.exports = async function build(program: BuildArgs) {
6747
if (program.profile) {
6848
report.warn(

packages/gatsby/src/commands/develop.ts

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { formatError } from "graphql"
1616

1717
import webpackConfig from "../utils/webpack.config"
1818
import bootstrap from "../bootstrap"
19-
import { store, emitter } from "../redux"
19+
import { store } from "../redux"
2020
import { syncStaticDir } from "../utils/get-static-dir"
2121
import { buildHTML } from "./build-html"
2222
import { withBasePath } from "../utils/path"
@@ -52,35 +52,17 @@ import {
5252
reportWebpackWarnings,
5353
structureWebpackErrors,
5454
} from "../utils/webpack-error-utils"
55+
import { waitUntilAllJobsComplete } from "../utils/commands/jobs-manager"
5556
import {
5657
userPassesFeedbackRequestHeuristic,
5758
showFeedbackRequest,
5859
} from "../utils/feedback"
5960

6061
import { BuildHTMLStage, IProgram } from "./types"
61-
import { waitUntilAllJobsComplete as waitUntilAllJobsV2Complete } from "../utils/jobs-manager"
6262

6363
// checks if a string is a valid ip
6464
const REGEX_IP = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])$/
6565

66-
const waitUntilAllJobsComplete = (): Promise<void> => {
67-
const jobsV1Promise = new Promise(resolve => {
68-
const onEndJob = (): void => {
69-
if (store.getState().jobs.active.length === 0) {
70-
resolve()
71-
emitter.off(`END_JOB`, onEndJob)
72-
}
73-
}
74-
emitter.on(`END_JOB`, onEndJob)
75-
onEndJob()
76-
})
77-
78-
return Promise.all([
79-
jobsV1Promise,
80-
waitUntilAllJobsV2Complete(),
81-
]).then(() => {})
82-
}
83-
8466
// const isInteractive = process.stdout.isTTY
8567

8668
// Watch the static directory and copy files to public as they're added or
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { emitter, store } from "../../redux"
2+
3+
import { waitUntilAllJobsComplete as waitUntilAllJobsV2Complete } from "../jobs-manager"
4+
5+
export const waitUntilAllJobsComplete = (): Promise<void> => {
6+
const jobsV1Promise = new Promise(resolve => {
7+
const onEndJob = (): void => {
8+
if (store.getState().jobs.active.length === 0) {
9+
resolve()
10+
emitter.off(`END_JOB`, onEndJob)
11+
}
12+
}
13+
14+
emitter.on(`END_JOB`, onEndJob)
15+
onEndJob()
16+
})
17+
18+
return Promise.all([
19+
jobsV1Promise,
20+
waitUntilAllJobsV2Complete(),
21+
]).then(() => {})
22+
}

0 commit comments

Comments
 (0)