Skip to content

Commit

Permalink
run scripts should go before mount scripts in build
Browse files Browse the repository at this point in the history
  • Loading branch information
FredKSchott committed May 30, 2020
1 parent 9b8be89 commit 9fb9f78
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 52 deletions.
92 changes: 46 additions & 46 deletions src/commands/build.ts
Expand Up @@ -124,6 +124,52 @@ export async function command(commandOptions: CommandOptions) {
});
}

for (const workerConfig of relevantWorkers) {
const {id, type, match} = workerConfig;
if (type !== 'run') {
continue;
}
messageBus.emit('WORKER_UPDATE', {id, state: ['RUNNING', 'yellow']});
const workerPromise = execa.command(workerConfig.cmd, {
env: npmRunPath.env(),
extendEnv: true,
shell: true,
cwd,
});
workerPromise.catch((err) => {
messageBus.emit('WORKER_MSG', {id, level: 'error', msg: err.toString()});
messageBus.emit('WORKER_COMPLETE', {id, error: err});
});
workerPromise.then(() => {
messageBus.emit('WORKER_COMPLETE', {id, error: null});
});
const {stdout, stderr} = workerPromise;
stdout?.on('data', (b) => {
let stdOutput = b.toString();
if (stdOutput.includes('\u001bc') || stdOutput.includes('\x1Bc')) {
messageBus.emit('WORKER_RESET', {id});
stdOutput = stdOutput.replace(/\x1Bc/, '').replace(/\u001bc/, '');
}
if (id.endsWith(':tsc')) {
if (stdOutput.includes('\u001bc') || stdOutput.includes('\x1Bc')) {
messageBus.emit('WORKER_UPDATE', {id, state: ['RUNNING', 'yellow']});
}
if (/Watching for file changes./gm.test(stdOutput)) {
messageBus.emit('WORKER_UPDATE', {id, state: 'WATCHING'});
}
const errorMatch = stdOutput.match(/Found (\d+) error/);
if (errorMatch && errorMatch[1] !== '0') {
messageBus.emit('WORKER_UPDATE', {id, state: ['ERROR', 'red']});
}
}
messageBus.emit('WORKER_MSG', {id, level: 'log', msg: stdOutput});
});
stderr?.on('data', (b) => {
messageBus.emit('WORKER_MSG', {id, level: 'error', msg: b.toString()});
});
await workerPromise;
}

const mountDirDetails: any[] = relevantWorkers
.map((scriptConfig) => {
const {id, type, args} = scriptConfig;
Expand Down Expand Up @@ -178,52 +224,6 @@ export async function command(commandOptions: CommandOptions) {
}
}

for (const workerConfig of relevantWorkers) {
const {id, type, match} = workerConfig;
if (type !== 'run') {
continue;
}
messageBus.emit('WORKER_UPDATE', {id, state: ['RUNNING', 'yellow']});
const workerPromise = execa.command(workerConfig.cmd, {
env: npmRunPath.env(),
extendEnv: true,
shell: true,
cwd,
});
workerPromise.catch((err) => {
messageBus.emit('WORKER_MSG', {id, level: 'error', msg: err.toString()});
messageBus.emit('WORKER_COMPLETE', {id, error: err});
});
workerPromise.then(() => {
messageBus.emit('WORKER_COMPLETE', {id, error: null});
});
const {stdout, stderr} = workerPromise;
stdout?.on('data', (b) => {
let stdOutput = b.toString();
if (stdOutput.includes('\u001bc') || stdOutput.includes('\x1Bc')) {
messageBus.emit('WORKER_RESET', {id});
stdOutput = stdOutput.replace(/\x1Bc/, '').replace(/\u001bc/, '');
}
if (id.endsWith(':tsc')) {
if (stdOutput.includes('\u001bc') || stdOutput.includes('\x1Bc')) {
messageBus.emit('WORKER_UPDATE', {id, state: ['RUNNING', 'yellow']});
}
if (/Watching for file changes./gm.test(stdOutput)) {
messageBus.emit('WORKER_UPDATE', {id, state: 'WATCHING'});
}
const errorMatch = stdOutput.match(/Found (\d+) error/);
if (errorMatch && errorMatch[1] !== '0') {
messageBus.emit('WORKER_UPDATE', {id, state: ['ERROR', 'red']});
}
}
messageBus.emit('WORKER_MSG', {id, level: 'log', msg: stdOutput});
});
stderr?.on('data', (b) => {
messageBus.emit('WORKER_MSG', {id, level: 'error', msg: b.toString()});
});
await workerPromise;
}

const allBuiltFromFiles = new Set<string>();
for (const workerConfig of relevantWorkers) {
const {id, match, type} = workerConfig;
Expand Down
12 changes: 6 additions & 6 deletions src/config.ts
Expand Up @@ -352,13 +352,13 @@ function normalizeScripts(cwd: string, scripts: RawScripts): BuildScript[] {
processedScripts.push(defaultBuildWorkerConfig);
}
processedScripts.sort((a, b) => {
if (a.id === 'mount:web_modules') {
return -1;
}
if (b.id === 'mount:web_modules') {
return 1;
}
if (a.type === b.type) {
if (a.id === 'mount:web_modules') {
return -1;
}
if (b.id === 'mount:web_modules') {
return 1;
}
return a.id.localeCompare(b.id);
}
return SCRIPT_TYPES_WEIGHTED[a.type] - SCRIPT_TYPES_WEIGHTED[b.type];
Expand Down

0 comments on commit 9fb9f78

Please sign in to comment.