refactor: deterministic monorepo
This commit is contained in:
parent
64e1d179c7
commit
8a47341cb6
25
.github/workflows/verify.yml
vendored
Normal file
25
.github/workflows/verify.yml
vendored
Normal file
|
@ -0,0 +1,25 @@
|
|||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ $default-branch ]
|
||||
pull_request:
|
||||
branches: [ $default-branch ]
|
||||
|
||||
jobs:
|
||||
verify:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [18.x, 20.x]
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
cache: 'npm'
|
||||
- run: npm ${{ vars.NPM_CI_FLAGS }} ci
|
||||
- run: npm run lint
|
||||
- run: npm run test
|
||||
- run: npm run build
|
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -127,4 +127,4 @@ dist
|
|||
/dox
|
||||
/dox-tmp
|
||||
|
||||
/.nx/cache
|
||||
/.actrc
|
||||
|
|
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
"eslint.workingDirectories": [{"pattern": "./packages/*"}],
|
||||
"eslint.options": {"overrideConfigFile": "../build/dist/build/eslint.config.js"},
|
||||
"eslint.options": {"overrideConfigFile": "../build/build/eslint.config.js"},
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
'@flecks/build': {}
|
||||
'@flecks/core:./packages/core': {}
|
||||
'@flecks/create:./packages/create-app': {}
|
||||
'@flecks/create:./packages/create-fleck': {}
|
||||
'@flecks/db:./packages/db': {}
|
||||
'@flecks/docker:./packages/docker': {}
|
||||
'@flecks/dox:./packages/dox':
|
||||
'@flecks/core': {}
|
||||
'@flecks/create-app': {}
|
||||
'@flecks/create-fleck': {}
|
||||
'@flecks/db': {}
|
||||
'@flecks/docker': {}
|
||||
'@flecks/dox':
|
||||
rewriteFilenames:
|
||||
-
|
||||
- '@flecks\/([^/]+)\/(.*)'
|
||||
|
@ -12,18 +12,18 @@
|
|||
-
|
||||
- '\((.*):([0-9]+):[0-9]+\)'
|
||||
- '($1#L$2)'
|
||||
'@flecks/electron:./packages/electron': {}
|
||||
'@flecks/fleck:./packages/fleck': {}
|
||||
'@flecks/passport:./packages/passport': {}
|
||||
'@flecks/passport-local:./packages/passport-local': {}
|
||||
'@flecks/passport-local-react:./packages/passport-local-react': {}
|
||||
'@flecks/passport-react:./packages/passport-react': {}
|
||||
'@flecks/react:./packages/react': {}
|
||||
'@flecks/react:./packages/react-redux': {}
|
||||
'@flecks/redis:./packages/redis': {}
|
||||
'@flecks/redux:./packages/redux': {}
|
||||
'@flecks/repl:./packages/repl': {}
|
||||
'@flecks/server:./packages/server': {}
|
||||
'@flecks/session:./packages/session': {}
|
||||
'@flecks/socket:./packages/socket': {}
|
||||
'@flecks/web:./packages/web': {}
|
||||
'@flecks/electron': {}
|
||||
'@flecks/fleck': {}
|
||||
'@flecks/passport': {}
|
||||
'@flecks/passport-local': {}
|
||||
'@flecks/passport-local-react': {}
|
||||
'@flecks/passport-react': {}
|
||||
'@flecks/react': {}
|
||||
'@flecks/react-redux': {}
|
||||
'@flecks/redis': {}
|
||||
'@flecks/redux': {}
|
||||
'@flecks/repl': {}
|
||||
'@flecks/server': {}
|
||||
'@flecks/session': {}
|
||||
'@flecks/socket': {}
|
||||
'@flecks/web': {}
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
{
|
||||
"packages": [
|
||||
"packages/*"
|
||||
],
|
||||
"useNx": true,
|
||||
"version": "3.2.4"
|
||||
}
|
||||
|
|
20319
package-lock.json
generated
Normal file
20319
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
|
@ -18,7 +18,10 @@
|
|||
"test": "lerna run test"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@flecks/build": "^3.1.3",
|
||||
"husky": "^9.0.7",
|
||||
"lerna": "^8.0.2"
|
||||
}
|
||||
},
|
||||
"workspaces": [
|
||||
"packages/*"
|
||||
]
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ const loadConfig = require('./load-config');
|
|||
const Resolver = require('./resolver');
|
||||
|
||||
const {
|
||||
FLECKS_CORE_BUILD_LIST = '',
|
||||
FLECKS_CORE_ROOT = process.cwd(),
|
||||
} = process.env;
|
||||
|
||||
|
@ -36,6 +37,13 @@ module.exports = class Build extends Flecks {
|
|||
]);
|
||||
}
|
||||
|
||||
static get buildList() {
|
||||
return FLECKS_CORE_BUILD_LIST
|
||||
.split(',')
|
||||
.map((name) => name.trim())
|
||||
.filter((e) => e);
|
||||
}
|
||||
|
||||
static async buildRuntime(originalConfig, platforms, flecks = {}) {
|
||||
const cleanConfig = JSON.parse(JSON.stringify(originalConfig));
|
||||
// Dealias the config keys.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
const D = require('@flecks/core/build/debug');
|
||||
const {processCode} = require('@flecks/core/server');
|
||||
const {processCode} = require('@flecks/core/src/server');
|
||||
const {Command} = require('commander');
|
||||
|
||||
const Build = require('./build');
|
||||
|
|
|
@ -20,7 +20,7 @@ const {
|
|||
add,
|
||||
lockFile,
|
||||
spawnWith,
|
||||
} = require('@flecks/core/server');
|
||||
} = require('@flecks/core/src/server');
|
||||
const {glob} = require('glob');
|
||||
const rimraf = require('rimraf');
|
||||
|
||||
|
@ -178,7 +178,7 @@ exports.commands = (program, flecks) => {
|
|||
debug('Building...', opts);
|
||||
const webpackConfig = await flecks.resolveBuildConfig('fleckspack.config.js');
|
||||
const cmd = [
|
||||
join(FLECKS_CORE_ROOT, 'node_modules', '.bin', 'webpack'),
|
||||
'npx', 'webpack',
|
||||
'--config', webpackConfig,
|
||||
'--mode', (production && !hot) ? 'production' : 'development',
|
||||
...((watch || hot) ? ['--watch'] : []),
|
||||
|
@ -210,7 +210,7 @@ exports.commands = (program, flecks) => {
|
|||
.map((pkg) => join(process.cwd(), pkg))
|
||||
.map(async (cwd) => {
|
||||
const cmd = [
|
||||
join(FLECKS_CORE_ROOT, 'node_modules', '.bin', 'eslint'),
|
||||
'npx', 'eslint',
|
||||
'--config', await flecks.resolveBuildConfig('eslint.config.js'),
|
||||
'.',
|
||||
];
|
||||
|
@ -219,7 +219,10 @@ exports.commands = (program, flecks) => {
|
|||
cmd,
|
||||
{
|
||||
cwd,
|
||||
env: {FLECKS_CORE_ROOT},
|
||||
env: {
|
||||
FLECKS_BUILD_ESLINT_NO_CACHE: true,
|
||||
FLECKS_CORE_ROOT,
|
||||
},
|
||||
},
|
||||
);
|
||||
child.on('error', reject);
|
||||
|
|
102
packages/build/build/common.webpack.config.js
Normal file
102
packages/build/build/common.webpack.config.js
Normal file
|
@ -0,0 +1,102 @@
|
|||
const {dirname, join} = require('path');
|
||||
|
||||
const {glob} = require('glob');
|
||||
|
||||
const {defaultConfig, regexFromExtensions} = require('./webpack');
|
||||
|
||||
const {
|
||||
FLECKS_CORE_ROOT = process.cwd(),
|
||||
} = process.env;
|
||||
|
||||
const source = join(FLECKS_CORE_ROOT, 'src');
|
||||
const tests = join(FLECKS_CORE_ROOT, 'test');
|
||||
|
||||
async function makeMonorepoResolve() {
|
||||
const resolve = {alias: {}, fallback: {}};
|
||||
const parts = FLECKS_CORE_ROOT.split('/');
|
||||
while (parts.length > 1) {
|
||||
parts.pop();
|
||||
try {
|
||||
const candidate = join(parts.join('/'), 'package.json');
|
||||
const {workspaces} = require(candidate);
|
||||
if (Array.isArray(workspaces)) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
const workspacePaths = await Promise.all(
|
||||
workspaces.map((workspace) => glob(join(dirname(candidate), workspace))),
|
||||
);
|
||||
workspacePaths
|
||||
.flat()
|
||||
.forEach((path) => {
|
||||
const {name} = require(join(path, 'package.json'));
|
||||
resolve.alias[name] = join(path, 'src');
|
||||
resolve.fallback[name] = path;
|
||||
});
|
||||
}
|
||||
}
|
||||
// eslint-disable-next-line no-empty
|
||||
catch (error) {}
|
||||
}
|
||||
return resolve;
|
||||
}
|
||||
|
||||
module.exports = async (env, argv, flecks) => {
|
||||
const {name} = require(join(FLECKS_CORE_ROOT, 'package.json'));
|
||||
const resolve = await makeMonorepoResolve();
|
||||
const config = defaultConfig(flecks, {
|
||||
node: {
|
||||
__dirname: false,
|
||||
__filename: false,
|
||||
},
|
||||
optimization: {
|
||||
splitChunks: false,
|
||||
runtimeChunk: false,
|
||||
},
|
||||
output: {
|
||||
filename: '[name].js',
|
||||
library: {
|
||||
name,
|
||||
type: 'umd',
|
||||
umdNamedDefine: true,
|
||||
},
|
||||
},
|
||||
plugins: [],
|
||||
resolve: {
|
||||
alias: {
|
||||
[name]: source,
|
||||
...resolve.alias,
|
||||
...flecks.resolver.aliases,
|
||||
},
|
||||
fallback: {
|
||||
[name]: FLECKS_CORE_ROOT,
|
||||
...resolve.fallback,
|
||||
...flecks.resolver.fallbacks,
|
||||
},
|
||||
modules: ['node_modules'],
|
||||
},
|
||||
stats: {
|
||||
colors: true,
|
||||
errorDetails: true,
|
||||
},
|
||||
target: 'node',
|
||||
});
|
||||
const babelConfig = await flecks.babel();
|
||||
const extensionsRegex = regexFromExtensions(config.resolve.extensions);
|
||||
config.module.rules.push(
|
||||
{
|
||||
include: [source, tests],
|
||||
test: extensionsRegex,
|
||||
use: [
|
||||
{
|
||||
loader: 'babel-loader',
|
||||
options: {
|
||||
cacheDirectory: true,
|
||||
babelrc: false,
|
||||
configFile: false,
|
||||
...babelConfig,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
);
|
||||
return config;
|
||||
};
|
|
@ -14,6 +14,7 @@ const Build = require('./build');
|
|||
const debug = D('@flecks/build/build/eslint.config.js');
|
||||
|
||||
const {
|
||||
FLECKS_BUILD_ESLINT_NO_CACHE,
|
||||
FLECKS_CORE_ROOT = process.cwd(),
|
||||
FLECKS_CORE_SYNC_FOR_ESLINT = false,
|
||||
} = process.env;
|
||||
|
@ -44,6 +45,9 @@ else {
|
|||
// Check cache first.
|
||||
const cacheDirectory = join(FLECKS_CORE_ROOT, 'node_modules', '.cache', '@flecks', 'build');
|
||||
try {
|
||||
if (FLECKS_BUILD_ESLINT_NO_CACHE) {
|
||||
throw new Error();
|
||||
}
|
||||
statSync(join(cacheDirectory, 'eslint.config.json'));
|
||||
module.exports = JSON.parse(readFileSync(join(cacheDirectory, 'eslint.config.json')).toString());
|
||||
}
|
||||
|
@ -62,7 +66,6 @@ else {
|
|||
const json = stdout.toString();
|
||||
try {
|
||||
const parsed = JSON.parse(json);
|
||||
statSync(join(FLECKS_CORE_ROOT, 'node_modules'));
|
||||
mkdirSync(cacheDirectory, {recursive: true});
|
||||
// Cache.
|
||||
writeFileSync(join(cacheDirectory, 'eslint.config.json'), json);
|
||||
|
|
|
@ -6,16 +6,15 @@ const {
|
|||
} = require('path');
|
||||
|
||||
const CopyPlugin = require('copy-webpack-plugin');
|
||||
const glob = require('glob');
|
||||
|
||||
const {defaultConfig, externals, regexFromExtensions} = require('./webpack');
|
||||
const configFn = require('./common.webpack.config');
|
||||
const {externals} = require('./webpack');
|
||||
|
||||
const {
|
||||
FLECKS_CORE_ROOT = process.cwd(),
|
||||
} = process.env;
|
||||
|
||||
const source = join(FLECKS_CORE_ROOT, 'src');
|
||||
const tests = join(FLECKS_CORE_ROOT, 'test');
|
||||
|
||||
const resolveValidModulePath = (source) => (path) => {
|
||||
// Does the file resolve as source?
|
||||
|
@ -36,79 +35,31 @@ const resolveValidModulePath = (source) => (path) => {
|
|||
};
|
||||
|
||||
module.exports = async (env, argv, flecks) => {
|
||||
const {name, files = []} = require(join(FLECKS_CORE_ROOT, 'package.json'));
|
||||
const config = defaultConfig(flecks, {
|
||||
externals: externals({importType: 'umd'}),
|
||||
node: {
|
||||
__dirname: false,
|
||||
__filename: false,
|
||||
},
|
||||
optimization: {
|
||||
splitChunks: false,
|
||||
runtimeChunk: false,
|
||||
},
|
||||
output: {
|
||||
filename: '[name].js',
|
||||
library: {
|
||||
name,
|
||||
type: 'umd',
|
||||
umdNamedDefine: true,
|
||||
},
|
||||
},
|
||||
plugins: [
|
||||
new CopyPlugin({
|
||||
patterns: [
|
||||
{
|
||||
from: '.',
|
||||
to: '.',
|
||||
globOptions: {
|
||||
dot: true,
|
||||
ignore: [
|
||||
'dist',
|
||||
'node_modules',
|
||||
],
|
||||
gitignore: true,
|
||||
},
|
||||
info: {
|
||||
minimized: true,
|
||||
},
|
||||
},
|
||||
],
|
||||
}),
|
||||
],
|
||||
resolve: {
|
||||
alias: {
|
||||
[name]: source,
|
||||
},
|
||||
fallback: {
|
||||
[name]: FLECKS_CORE_ROOT,
|
||||
},
|
||||
},
|
||||
stats: {
|
||||
colors: true,
|
||||
errorDetails: true,
|
||||
},
|
||||
target: 'node',
|
||||
});
|
||||
const babelConfig = await flecks.babel();
|
||||
const extensionsRegex = regexFromExtensions(config.resolve.extensions);
|
||||
config.module.rules.push(
|
||||
{
|
||||
include: [source, tests],
|
||||
test: extensionsRegex,
|
||||
use: [
|
||||
const config = await configFn(env, argv, flecks);
|
||||
config.externals = await externals();
|
||||
config.output.clean = {keep: /test\.js(?:\.map)?/};
|
||||
config.plugins.push(
|
||||
new CopyPlugin({
|
||||
patterns: [
|
||||
{
|
||||
loader: 'babel-loader',
|
||||
options: {
|
||||
cacheDirectory: true,
|
||||
babelrc: false,
|
||||
configFile: false,
|
||||
...babelConfig,
|
||||
from: '.',
|
||||
to: '.',
|
||||
globOptions: {
|
||||
dot: true,
|
||||
ignore: [
|
||||
'dist',
|
||||
'node_modules',
|
||||
],
|
||||
gitignore: true,
|
||||
},
|
||||
info: {
|
||||
minimized: true,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
}),
|
||||
);
|
||||
const {files = []} = require(join(FLECKS_CORE_ROOT, 'package.json'));
|
||||
// Automatic entry registration.
|
||||
files
|
||||
.filter(resolveValidModulePath(source))
|
||||
|
@ -116,14 +67,5 @@ module.exports = async (env, argv, flecks) => {
|
|||
const trimmed = join(dirname(file), basename(file, extname(file)));
|
||||
config.entry[trimmed] = `${source}/${trimmed}`;
|
||||
});
|
||||
// Test entry.
|
||||
const testPaths = glob.sync(join(tests, '*.js'));
|
||||
const {platforms} = flecks;
|
||||
for (let i = 0; i < platforms.length; ++i) {
|
||||
testPaths.push(...glob.sync(join(tests, platforms[i], '*.js')));
|
||||
}
|
||||
if (testPaths.length > 0) {
|
||||
config.entry.test = ['source-map-support/register', ...testPaths];
|
||||
}
|
||||
return config;
|
||||
};
|
||||
|
|
|
@ -4,6 +4,7 @@ const webpack = require('webpack');
|
|||
|
||||
const {commands} = require('./commands');
|
||||
const {ProcessAssets} = require('./process-assets');
|
||||
const {externals} = require('./webpack');
|
||||
|
||||
const {
|
||||
FLECKS_CORE_ROOT = process.cwd(),
|
||||
|
@ -25,6 +26,13 @@ exports.hooks = {
|
|||
}
|
||||
config.plugins.push(new ProcessAssets(target, flecks));
|
||||
},
|
||||
'@flecks/build.config.alter': async ({test}) => {
|
||||
if (test) {
|
||||
test.externals = await externals({
|
||||
allowlist: Object.keys(test.resolve.fallback).map((fallback) => new RegExp(fallback)),
|
||||
});
|
||||
}
|
||||
},
|
||||
'@flecks/build.files': () => [
|
||||
/**
|
||||
* Babel configuration. See: https://babeljs.io/docs/en/config-files
|
||||
|
@ -44,9 +52,13 @@ exports.hooks = {
|
|||
*/
|
||||
'fleckspack.config.js',
|
||||
/**
|
||||
* Fleck build configuration. See: https://webpack.js.org/configuration/
|
||||
* Fleck source build configuration. See: https://webpack.js.org/configuration/
|
||||
*/
|
||||
'fleck.webpack.config.js',
|
||||
/**
|
||||
* Fleck test build configuration. See: https://webpack.js.org/configuration/
|
||||
*/
|
||||
'test.webpack.config.js',
|
||||
],
|
||||
'@flecks/core.config': () => ({
|
||||
/**
|
||||
|
|
|
@ -6,14 +6,7 @@ const Build = require('./build');
|
|||
|
||||
const debug = D('@flecks/build/build/fleckspack.config.js');
|
||||
|
||||
const {
|
||||
FLECKS_CORE_BUILD_LIST = '',
|
||||
} = process.env;
|
||||
|
||||
const buildList = FLECKS_CORE_BUILD_LIST
|
||||
.split(',')
|
||||
.map((name) => name.trim())
|
||||
.filter((e) => e);
|
||||
const {buildList} = Build;
|
||||
|
||||
module.exports = async (env, argv) => {
|
||||
debug('bootstrapping flecks...');
|
||||
|
|
28
packages/build/build/test.webpack.config.js
Normal file
28
packages/build/build/test.webpack.config.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
const {join} = require('path');
|
||||
|
||||
const {glob} = require('glob');
|
||||
|
||||
const configFn = require('./common.webpack.config');
|
||||
|
||||
const {
|
||||
FLECKS_CORE_ROOT = process.cwd(),
|
||||
} = process.env;
|
||||
|
||||
const tests = join(FLECKS_CORE_ROOT, 'test');
|
||||
|
||||
module.exports = async (env, argv, flecks) => {
|
||||
const config = await configFn(env, argv, flecks);
|
||||
config.output.chunkFormat = false;
|
||||
config.output.clean = false;
|
||||
// Test entry.
|
||||
const testPaths = await glob(join(tests, '*.js'));
|
||||
const {platforms} = flecks;
|
||||
testPaths.push(
|
||||
...(await Promise.all(platforms.map((platform) => glob(join(tests, platform, '*.js')))))
|
||||
.flat(),
|
||||
);
|
||||
if (testPaths.length > 0) {
|
||||
config.entry.test = ['source-map-support/register', ...testPaths];
|
||||
}
|
||||
return config;
|
||||
};
|
|
@ -1,4 +1,4 @@
|
|||
const {chmod} = require('fs');
|
||||
const {access, chmod} = require('fs/promises');
|
||||
const {join} = require('path');
|
||||
|
||||
const CopyPlugin = require('copy-webpack-plugin');
|
||||
|
@ -94,18 +94,47 @@ exports.executable = () => (
|
|||
|
||||
// eslint-disable-next-line class-methods-use-this
|
||||
apply(compiler) {
|
||||
compiler.hooks.afterEmit.tapAsync(
|
||||
compiler.hooks.afterEmit.tapPromise(
|
||||
'Executable',
|
||||
(compilation, callback) => {
|
||||
chmod(join(FLECKS_CORE_ROOT, 'dist', 'build', 'cli.js'), 0o755, callback);
|
||||
},
|
||||
async () => (
|
||||
chmod(join(FLECKS_CORE_ROOT, 'dist', 'build', 'cli.js'), 0o755)
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}()
|
||||
);
|
||||
|
||||
exports.externals = nodeExternals;
|
||||
exports.externals = async (options = {}) => {
|
||||
const parts = FLECKS_CORE_ROOT.split('/');
|
||||
const additionalModuleDirs = [];
|
||||
while (parts.length > 1) {
|
||||
parts.pop();
|
||||
const candidate = join(parts.join('/'), 'node_modules');
|
||||
try {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await access(candidate);
|
||||
additionalModuleDirs.push(candidate);
|
||||
}
|
||||
// eslint-disable-next-line no-empty
|
||||
catch (error) {}
|
||||
}
|
||||
try {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await access('/node_modules');
|
||||
additionalModuleDirs.push('/node_modules');
|
||||
}
|
||||
// eslint-disable-next-line no-empty
|
||||
catch (error) {}
|
||||
return nodeExternals({
|
||||
importType: 'umd',
|
||||
...options,
|
||||
additionalModuleDirs: [
|
||||
...additionalModuleDirs,
|
||||
...(options.additionalModuleDirs || []),
|
||||
],
|
||||
});
|
||||
};
|
||||
|
||||
exports.regexFromExtensions = (exts) => (
|
||||
new RegExp(String.raw`(?:${exts.map((ext) => ext.replaceAll('.', '\\.')).join('|')})$`)
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
"clean": "rm -rf dist node_modules yarn.lock",
|
||||
"lint": "eslint --config ./build/eslint.config.js .",
|
||||
"postversion": "npm run build",
|
||||
"test": "npm run build -d && mocha -t 10000 --colors ./dist/test.js"
|
||||
"test": "webpack --config ../core/build/test.webpack.config.js --mode production && mocha --colors ./dist/test.js"
|
||||
},
|
||||
"bin": {
|
||||
"flecks": "./build/cli.js"
|
||||
|
|
|
@ -1,4 +1,10 @@
|
|||
export {dump as dumpYml, load as loadYml} from 'js-yaml';
|
||||
export {default as webpack} from 'webpack';
|
||||
/* eslint-disable global-require */
|
||||
|
||||
export * from '../build/webpack';
|
||||
const {dump: dumpYml, load: loadYml} = require('js-yaml');
|
||||
|
||||
module.exports = {
|
||||
dumpYml,
|
||||
loadYml,
|
||||
webpack: require('webpack'),
|
||||
...require('../build/webpack'),
|
||||
};
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import {mkdir, writeFile} from 'fs/promises';
|
||||
import {join} from 'path';
|
||||
|
||||
import {expect} from 'chai';
|
||||
|
@ -89,6 +90,9 @@ describe('explication', () => {
|
|||
});
|
||||
|
||||
it('includes modules', async () => {
|
||||
// act doesn't like copying node_modules, so we'll spin it up.
|
||||
mkdir(join(root, 'modules-root', 'node_modules'));
|
||||
await writeFile(join(root, 'modules-root', 'node_modules', 'foo.js'), '');
|
||||
expect(await createExplication(['modules-root:./modules-root', 'foo']))
|
||||
.to.deep.include({
|
||||
paths: ['modules-root', 'foo'],
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
'@flecks/build:../build': {}
|
||||
'@flecks/core:.': {}
|
8
packages/core/build/test.webpack.config.js
Normal file
8
packages/core/build/test.webpack.config.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
const Build = require('../../build/build/build');
|
||||
const configFn = require('../../build/build/test.webpack.config');
|
||||
|
||||
module.exports = async (env, argv) => {
|
||||
const flecks = await Build.from();
|
||||
const config = await configFn(env, argv, flecks);
|
||||
return config;
|
||||
};
|
|
@ -8,7 +8,7 @@
|
|||
"clean": "rm -rf dist node_modules yarn.lock",
|
||||
"lint": "eslint --config ./build/core.eslint.config.js .",
|
||||
"postversion": "npm run build",
|
||||
"test": "npm run build -d && mocha --colors ./dist/test.js"
|
||||
"test": "webpack --config ./build/test.webpack.config.js --mode production && mocha --colors ./dist/test.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
@ -41,7 +41,6 @@
|
|||
"babel-merge": "^3.0.0",
|
||||
"chai": "4.2.0",
|
||||
"chai-as-promised": "7.1.1",
|
||||
"clear-module": "^4.1.2",
|
||||
"copy-webpack-plugin": "^11.0.0",
|
||||
"eslint": "^8.56.0",
|
||||
"eslint-config-airbnb": "^19.0.4",
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
export {default as Class} from '../build/class';
|
||||
export {default as compose} from '../build/compose';
|
||||
export {default as D} from '../build/debug';
|
||||
export {default as EventEmitter} from '../build/event-emitter';
|
||||
export {
|
||||
ById,
|
||||
ByType,
|
||||
Flecks,
|
||||
} from '../build/flecks';
|
||||
/* eslint-disable global-require */
|
||||
|
||||
export const hooks = {
|
||||
'@flecks/web.config': async (req, flecks) => ({
|
||||
id: flecks.get('@flecks/core.id'),
|
||||
}),
|
||||
module.exports = {
|
||||
Class: require('../build/class'),
|
||||
compose: require('../build/compose'),
|
||||
D: require('../build/debug'),
|
||||
EventEmitter: require('../build/event-emitter'),
|
||||
...require('../build/flecks'),
|
||||
hooks: {
|
||||
'@flecks/web.config': async (req, flecks) => ({
|
||||
id: flecks.get('@flecks/core.id'),
|
||||
}),
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
export {glob} from 'glob';
|
||||
/* eslint-disable global-require */
|
||||
|
||||
export * from '../../build/stream';
|
||||
export * from './package-manager';
|
||||
export * from './process';
|
||||
module.exports = {
|
||||
glob: require('glob').glob,
|
||||
...require('../../build/stream'),
|
||||
...require('./package-manager'),
|
||||
...require('./process'),
|
||||
};
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
import {processCode, spawnWith} from './process';
|
||||
const {processCode, spawnWith} = require('./process');
|
||||
|
||||
/* eslint-disable camelcase */
|
||||
const {
|
||||
npm_config_user_agent = 'npm',
|
||||
} = process.env;
|
||||
|
||||
export const inferPackageManager = () => npm_config_user_agent.split('/')[0];
|
||||
exports.inferPackageManager = () => npm_config_user_agent.split('/')[0];
|
||||
/* eslint-enable camelcase */
|
||||
|
||||
export const build = async ({cwd, packageManager = inferPackageManager()}) => {
|
||||
exports.build = async ({cwd, packageManager = exports.inferPackageManager()}) => {
|
||||
let args;
|
||||
switch (packageManager) {
|
||||
case 'bun':
|
||||
|
@ -28,7 +28,7 @@ export const build = async ({cwd, packageManager = inferPackageManager()}) => {
|
|||
return args && processCode(spawnWith(args, {cwd}));
|
||||
};
|
||||
|
||||
export const add = async ({dev, packageManager = inferPackageManager(), packages}) => {
|
||||
exports.add = async ({dev, packageManager = exports.inferPackageManager(), packages}) => {
|
||||
let args;
|
||||
switch (packageManager) {
|
||||
case 'bun':
|
||||
|
@ -64,7 +64,7 @@ export const add = async ({dev, packageManager = inferPackageManager(), packages
|
|||
return args && processCode(spawnWith(args));
|
||||
};
|
||||
|
||||
export const install = async ({cwd, packageManager = inferPackageManager()}) => {
|
||||
exports.install = async ({cwd, packageManager = exports.inferPackageManager()}) => {
|
||||
let args;
|
||||
switch (packageManager) {
|
||||
case 'bun':
|
||||
|
@ -84,7 +84,7 @@ export const install = async ({cwd, packageManager = inferPackageManager()}) =>
|
|||
return args && processCode(spawnWith(args, {cwd}));
|
||||
};
|
||||
|
||||
export const lockFile = (packageManager = inferPackageManager()) => {
|
||||
exports.lockFile = (packageManager = exports.inferPackageManager()) => {
|
||||
switch (packageManager) {
|
||||
case 'bun':
|
||||
return 'bun.lockb';
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import {spawn} from 'child_process';
|
||||
const {spawn} = require('child_process');
|
||||
|
||||
import D from '../../build/debug';
|
||||
const D = require('../../build/debug');
|
||||
|
||||
const debug = D('@flecks/core/server');
|
||||
const debugSilly = debug.extend('silly');
|
||||
|
||||
export const processCode = (child) => new Promise((resolve, reject) => {
|
||||
exports.processCode = (child) => new Promise((resolve, reject) => {
|
||||
child.on('error', reject);
|
||||
child.on('exit', (code) => {
|
||||
child.off('error', reject);
|
||||
|
@ -13,7 +13,7 @@ export const processCode = (child) => new Promise((resolve, reject) => {
|
|||
});
|
||||
});
|
||||
|
||||
export const spawnWith = (cmd, opts = {}) => {
|
||||
exports.spawnWith = (cmd, opts = {}) => {
|
||||
debug("spawning: '%s'", cmd.join(' '));
|
||||
debugSilly('with options: %O', opts);
|
||||
const child = spawn(cmd[0], cmd.slice(1), {
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
/* eslint-disable camelcase */
|
||||
|
||||
import {join} from 'path';
|
||||
|
||||
import {expect} from 'chai';
|
||||
import clearModule from 'clear-module';
|
||||
|
||||
import resolve from '@flecks/core/build/resolve';
|
||||
|
||||
|
@ -21,10 +22,10 @@ it('can resolve inexact', async () => {
|
|||
expect(__non_webpack_require__(join(root, 'blah')))
|
||||
.to.equal(4);
|
||||
clear();
|
||||
clearModule(join(root, 'blah'));
|
||||
delete __non_webpack_require__.cache['/home/cha0s/sync/src/code/flecks/packages/core/test/server/resolve/blah.js'];
|
||||
expect(__non_webpack_require__(join(root, 'blah')))
|
||||
.to.equal(3);
|
||||
clearModule(join(root, 'blah'));
|
||||
delete __non_webpack_require__.cache['/home/cha0s/sync/src/code/flecks/packages/core/test/server/resolve/blah.js'];
|
||||
});
|
||||
|
||||
it('can resolve exact', async () => {
|
||||
|
@ -39,11 +40,11 @@ it('can resolve exact', async () => {
|
|||
expect(__non_webpack_require__(join(root, 'boo')))
|
||||
.to.equal(2);
|
||||
clear();
|
||||
clearModule(join(root, 'blah'));
|
||||
clearModule(join(root, 'boo'));
|
||||
delete __non_webpack_require__.cache['/home/cha0s/sync/src/code/flecks/packages/core/test/server/resolve/blah.js'];
|
||||
delete __non_webpack_require__.cache['/home/cha0s/sync/src/code/flecks/packages/core/test/server/resolve/boo.js'];
|
||||
expect(__non_webpack_require__(join(root, 'boo')))
|
||||
.to.equal(1);
|
||||
clearModule(join(root, 'boo'));
|
||||
delete __non_webpack_require__.cache['/home/cha0s/sync/src/code/flecks/packages/core/test/server/resolve/boo.js'];
|
||||
});
|
||||
|
||||
it('can resolve false', async () => {
|
||||
|
@ -53,10 +54,10 @@ it('can resolve false', async () => {
|
|||
},
|
||||
fallback: {},
|
||||
}, []);
|
||||
expect(__non_webpack_require__(join(root, 'boo')))
|
||||
expect(__non_webpack_require__(join(root, 'boo.js')))
|
||||
.to.be.undefined;
|
||||
clear();
|
||||
clearModule(join(root, 'boo'));
|
||||
expect(__non_webpack_require__(join(root, 'boo')))
|
||||
delete __non_webpack_require__.cache['/home/cha0s/sync/src/code/flecks/packages/core/test/server/resolve/boo.js'];
|
||||
expect(__non_webpack_require__(join(root, 'boo.js')))
|
||||
.to.equal(1);
|
||||
});
|
||||
|
|
0
packages/create-app/build/cli.js
Normal file → Executable file
0
packages/create-app/build/cli.js
Normal file → Executable file
|
@ -1,4 +1,4 @@
|
|||
const {copy, executable} = require('@flecks/build/server');
|
||||
const {copy, executable} = require('@flecks/build/src/server');
|
||||
const configFn = require('@flecks/fleck/build/fleck.webpack.config');
|
||||
|
||||
module.exports = async (env, argv, flecks) => {
|
||||
|
|
2
packages/create-fleck/build/cli.js
Normal file → Executable file
2
packages/create-fleck/build/cli.js
Normal file → Executable file
|
@ -11,7 +11,7 @@ const {
|
|||
transform,
|
||||
} = require('@flecks/core/server');
|
||||
const {move, testDestination} = require('@flecks/create-app/build/move');
|
||||
const {validate} = require('@flecks/create-app/server');
|
||||
const {validate} = require('@flecks/create-app/src/server');
|
||||
|
||||
const {
|
||||
FLECKS_CORE_ROOT = process.cwd(),
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
const {copy, executable} = require('@flecks/build/server');
|
||||
const {copy, executable} = require('@flecks/build/src/server');
|
||||
const configFn = require('@flecks/fleck/build/fleck.webpack.config');
|
||||
|
||||
module.exports = async (env, argv, flecks) => {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
const {dumpYml} = require('@flecks/build/server');
|
||||
const {dumpYml} = require('@flecks/build/src/server');
|
||||
|
||||
const {generateComposeConfig, generateDockerFile} = require('./generate');
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ const {dirname, join, relative} = require('path');
|
|||
|
||||
const {transformAsync} = require('@babel/core');
|
||||
const {default: traverse} = require('@babel/traverse');
|
||||
const {glob} = require('@flecks/core/server');
|
||||
const {glob} = require('@flecks/core/src/server');
|
||||
|
||||
const {
|
||||
buildFileVisitor,
|
||||
|
|
|
@ -3,8 +3,8 @@ const {join} = require('path');
|
|||
|
||||
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||
const {commands: coreCommands} = require('@flecks/build/build/commands');
|
||||
const {D} = require('@flecks/core');
|
||||
const {glob} = require('@flecks/core/server');
|
||||
const {D} = require('@flecks/core/src');
|
||||
const {glob} = require('@flecks/core/src/server');
|
||||
const chokidar = require('chokidar');
|
||||
const clearModule = require('clear-module');
|
||||
const Mocha = require('mocha');
|
||||
|
@ -33,7 +33,7 @@ module.exports = (program, flecks) => {
|
|||
watch,
|
||||
} = opts;
|
||||
const {build} = coreCommands(program, flecks);
|
||||
const child = await build.action(undefined, opts);
|
||||
const child = await build.action('test', opts);
|
||||
const testPaths = await glob(join(FLECKS_CORE_ROOT, 'test/**/*.js'));
|
||||
if (0 === testPaths.length) {
|
||||
// eslint-disable-next-line no-console
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
const Build = require('@flecks/build/build/build');
|
||||
const {processFleckAssets} = require('@flecks/build/build/process-assets');
|
||||
|
||||
const commands = require('./commands');
|
||||
|
@ -13,7 +14,10 @@ exports.hooks = {
|
|||
errorDetails: true,
|
||||
},
|
||||
}),
|
||||
'@flecks/build.targets': () => ['fleck'],
|
||||
'@flecks/build.targets': () => (
|
||||
['fleck']
|
||||
.concat(Build.buildList.includes('test') ? ['test'] : [])
|
||||
),
|
||||
'@flecks/build.processAssets': async (target, assets, compilation, flecks) => {
|
||||
if ('fleck' === target) {
|
||||
await processFleckAssets(assets, compilation, (json, compilation) => (
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
const {externals} = require('@flecks/build/server');
|
||||
const {externals} = require('@flecks/build/src/server');
|
||||
const configFn = require('@flecks/fleck/build/fleck.webpack.config');
|
||||
|
||||
module.exports = async (env, argv, flecks) => {
|
||||
const config = await configFn(env, argv, flecks);
|
||||
config.externals = externals({
|
||||
config.externals = await externals({
|
||||
allowlist: ['react-tabs/style/react-tabs.css'],
|
||||
importType: 'umd',
|
||||
});
|
||||
return config;
|
||||
};
|
||||
|
|
|
@ -3,7 +3,7 @@ const {readdir} = require('fs/promises');
|
|||
const {tmpdir} = require('os');
|
||||
const {join} = require('path');
|
||||
|
||||
const {D} = require('@flecks/core');
|
||||
const {D} = require('@flecks/core/src');
|
||||
const commandExists = require('command-exists');
|
||||
|
||||
const debug = D('@flecks/repl/commands');
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
const {banner} = require('@flecks/build/server');
|
||||
const {banner} = require('@flecks/build/src/server');
|
||||
|
||||
exports.hooks = {
|
||||
'@flecks/build.config.alter': ({server}, env, argv, flecks) => {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
const {externals} = require('@flecks/build/server');
|
||||
const {externals} = require('@flecks/build/src/server');
|
||||
|
||||
const D = require('@flecks/core/build/debug');
|
||||
|
||||
|
@ -106,5 +106,9 @@ module.exports = async (config, env, argv, flecks) => {
|
|||
allowlist.push(/^webpack\/hot\/signal/);
|
||||
}
|
||||
// Externalize the rest.
|
||||
config.externals = externals({allowlist, additionalModuleDirs: flecks.resolver.modules});
|
||||
config.externals = await externals({
|
||||
additionalModuleDirs: flecks.resolver.modules,
|
||||
allowlist,
|
||||
importType: 'commonjs',
|
||||
});
|
||||
};
|
||||
|
|
|
@ -4,7 +4,7 @@ const {
|
|||
banner,
|
||||
defaultConfig,
|
||||
webpack,
|
||||
} = require('@flecks/build/server');
|
||||
} = require('@flecks/build/src/server');
|
||||
|
||||
const runtime = require('./runtime');
|
||||
const startServer = require('./start');
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
const {copy, externals} = require('@flecks/build/server');
|
||||
const {copy, externals} = require('@flecks/build/src/server');
|
||||
const configFn = require('@flecks/fleck/build/fleck.webpack.config');
|
||||
|
||||
module.exports = async (env, argv, flecks) => {
|
||||
|
@ -6,9 +6,8 @@ module.exports = async (env, argv, flecks) => {
|
|||
delete config.entry['server/build/entry'];
|
||||
delete config.entry['server/build/template'];
|
||||
delete config.entry['server/build/tests'];
|
||||
config.externals = externals({
|
||||
config.externals = await externals({
|
||||
allowlist: ['mocha/mocha.css'],
|
||||
importType: 'umd',
|
||||
});
|
||||
config.plugins.push(
|
||||
copy({
|
||||
|
|
|
@ -2,8 +2,8 @@ const {stat, unlink} = require('fs/promises');
|
|||
const {join} = require('path');
|
||||
|
||||
const Build = require('@flecks/build/build/build');
|
||||
const {regexFromExtensions} = require('@flecks/build/server');
|
||||
const {spawnWith} = require('@flecks/core/server');
|
||||
const {regexFromExtensions} = require('@flecks/build/src/server');
|
||||
const {spawnWith} = require('@flecks/core/src/server');
|
||||
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
||||
|
||||
const {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
const {join} = require('path');
|
||||
|
||||
const {defaultConfig, webpack} = require('@flecks/build/server');
|
||||
const {defaultConfig, webpack} = require('@flecks/build/src/server');
|
||||
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
|
||||
|
||||
const {
|
||||
|
|
|
@ -4,7 +4,7 @@ const {
|
|||
defaultConfig,
|
||||
regexFromExtensions,
|
||||
webpack,
|
||||
} = require('@flecks/build/server');
|
||||
} = require('@flecks/build/src/server');
|
||||
const AddAssetHtmlPlugin = require('add-asset-html-webpack-plugin');
|
||||
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||
const {htmlTagObjectToString} = require('html-webpack-plugin/lib/html-tags');
|
||||
|
|
Loading…
Reference in New Issue
Block a user