Skip to content

Commit

Permalink
fix: various nits with process lifetime and streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
cha0s committed Feb 21, 2024
1 parent 8fed3a3 commit ee65af6
Show file tree
Hide file tree
Showing 16 changed files with 298 additions and 57 deletions.
164 changes: 150 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"packages/*"
],
"devDependencies": {
"@npmcli/arborist": "^7.3.1",
"chalk": "^4.1.2"
"@npmcli/arborist": "^7.3.1"
}
}
1 change: 1 addition & 0 deletions packages/build/build/default.eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ module.exports = async (flecks) => ({
'import/prefer-default-export': 'off',
'jsx-a11y/control-has-associated-label': ['error', {assert: 'either'}],
'jsx-a11y/label-has-associated-control': ['error', {assert: 'either'}],
'max-classes-per-file': ['error', {ignoreExpressions: true}],
'no-param-reassign': ['error', {props: false}],
'no-plusplus': 'off',
'no-shadow': 'off',
Expand Down
31 changes: 26 additions & 5 deletions packages/build/build/hooks/@flecks/build.commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const {
} = require('@babel/types');
const addPathsToYml = require('@flecks/core/build/add-paths-to-yml');
const D = require('@flecks/core/build/debug');
const {prefixLines} = require('@flecks/core/build/stream');
const {
add,
binaryPath,
Expand All @@ -28,6 +29,7 @@ const {
spawnWith,
writeFile,
} = require('@flecks/core/src/server');
const chalk = require('chalk');
const chokidar = require('chokidar');
const {glob} = require('glob');
const {paperwork} = require('precinct');
Expand Down Expand Up @@ -224,24 +226,43 @@ exports.hook = (program, flecks) => {
'--mode', (production && !hot) ? 'production' : 'development',
];
const options = {
// @todo This kills the pnpm. Let's use a real IPC channel.
useFork: true,
stdio: ['pipe', 'pipe', 'pipe', 'ipc'],
...rest,
env: {
DEBUG_COLORS: process.stdout.isTTY,
FLECKS_BUILD_IS_PRODUCTION: production,
FORCE_COLOR: process.stdout.isTTY,
...(target ? {FLECKS_CORE_BUILD_LIST: target} : {}),
...(hot ? {FLECKS_ENV__flecks_server__hot: 'true'} : {}),
...rest.env,
},
};
const spawnWithPrefixedLines = (cmd, options) => {
const child = spawnWith(cmd, options);
if (
'pipe' === options.stdio
|| (Array.isArray(options.stdio) && options.stdio[0] === 'pipe')
) {
prefixLines(child.stdout, chalk.green('[📦] '))
.pipe(process.stdout);
}
if (
'pipe' === options.stdio
|| (Array.isArray(options.stdio) && options.stdio[1] === 'pipe')
) {
prefixLines(child.stderr, chalk.green('[📦] '))
.pipe(process.stderr);
}
return child;
};
if (!watch) {
return spawnWith(cmd, options);
return spawnWithPrefixedLines(cmd, options);
}
try {
await access(join(FLECKS_CORE_ROOT, 'build/flecks.yml'));
}
catch (error) {
return spawnWith(cmd, options);
return spawnWithPrefixedLines(cmd, options);
}
await rootsDependencies(flecks.roots, flecks.resolver);
const watched = Object.keys(dependencies);
Expand All @@ -259,7 +280,7 @@ exports.hook = (program, flecks) => {
});
let webpack;
const spawnWebpack = () => {
webpack = spawnWith(cmd, options);
webpack = spawnWithPrefixedLines(cmd, options);
webpack.on('message', (message) => {
switch (message.type) {
case 'kill':
Expand Down
1 change: 1 addition & 0 deletions packages/build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"babel-merge": "^3.0.0",
"chai": "4.2.0",
"chai-as-promised": "7.1.1",
"chalk": "^4.1.2",
"chokidar": "^3.5.3",
"commander": "11.1.0",
"copy-webpack-plugin": "^11.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/build/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = (name) => {
D.formatters.o = undefined;
D.formatters.O = undefined;
}
const type = 'web' === process.env.FLECKS_CORE_BUILD_TARGET ? 'debug' : 'error';
const type = 'undefined' !== typeof window ? 'log' : 'error';
// eslint-disable-next-line no-console
D.log = console[type].bind(console);
}
Expand Down

0 comments on commit ee65af6

Please sign in to comment.