balm-core 6.0.0-alpha.2 → 6.0.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/index.cjs +395 -111
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +21 -3
  5. package/dist/index.d.ts +21 -3
  6. package/dist/index.js +381 -97
  7. package/dist/index.js.map +1 -1
  8. package/package.json +38 -1
  9. package/src/balm.ts +0 -107
  10. package/src/bundler/esbuild.ts +0 -48
  11. package/src/bundler/index.ts +0 -3
  12. package/src/bundler/rollup.ts +0 -46
  13. package/src/bundler/webpack.ts +0 -125
  14. package/src/config/constants.ts +0 -12
  15. package/src/config/defaults.ts +0 -212
  16. package/src/config/index.ts +0 -112
  17. package/src/hooks/index.ts +0 -224
  18. package/src/index.ts +0 -16
  19. package/src/pipeline/file.ts +0 -69
  20. package/src/pipeline/index.ts +0 -10
  21. package/src/pipeline/pipeline.ts +0 -135
  22. package/src/pipeline/transforms/cache.ts +0 -147
  23. package/src/pipeline/transforms/htmlmin.ts +0 -18
  24. package/src/pipeline/transforms/less.ts +0 -75
  25. package/src/pipeline/transforms/postcss.ts +0 -43
  26. package/src/pipeline/transforms/rename.ts +0 -38
  27. package/src/pipeline/transforms/replace.ts +0 -30
  28. package/src/pipeline/transforms/sass.ts +0 -106
  29. package/src/pipeline/transforms/terser.ts +0 -20
  30. package/src/runner/dag.ts +0 -77
  31. package/src/runner/task.ts +0 -38
  32. package/src/shims.d.ts +0 -5
  33. package/src/tasks/cache.ts +0 -84
  34. package/src/tasks/clean.ts +0 -21
  35. package/src/tasks/copy.ts +0 -36
  36. package/src/tasks/ftp.ts +0 -90
  37. package/src/tasks/html.ts +0 -290
  38. package/src/tasks/index.ts +0 -14
  39. package/src/tasks/publish.ts +0 -71
  40. package/src/tasks/pwa.ts +0 -86
  41. package/src/tasks/remove.ts +0 -24
  42. package/src/tasks/replace.ts +0 -34
  43. package/src/tasks/script.ts +0 -28
  44. package/src/tasks/server.ts +0 -218
  45. package/src/tasks/static.ts +0 -77
  46. package/src/tasks/style.ts +0 -57
  47. package/src/tasks/zip.ts +0 -77
  48. package/src/types/index.ts +0 -225
  49. package/src/utilities/file.ts +0 -140
  50. package/src/utilities/logger.ts +0 -63
  51. package/src/utilities/utils.ts +0 -46
  52. package/src/utilities/workspace.ts +0 -38
  53. package/src/watcher/index.ts +0 -100
  54. package/tsconfig.json +0 -8
  55. package/tsup.config.ts +0 -12
package/package.json CHANGED
@@ -1,8 +1,32 @@
1
1
  {
2
2
  "name": "balm-core",
3
- "version": "6.0.0-alpha.2",
3
+ "version": "6.0.0-alpha.3",
4
4
  "type": "module",
5
5
  "description": "Next-generation core build engine for BalmJS",
6
+ "keywords": [
7
+ "balm",
8
+ "balmjs",
9
+ "web",
10
+ "app",
11
+ "front-end",
12
+ "workflow"
13
+ ],
14
+ "homepage": "https://balm.js.org",
15
+ "license": "MIT",
16
+ "author": {
17
+ "name": "Elf-mousE",
18
+ "email": "ifmouz@gmail.com",
19
+ "url": "http://elf-mouse.me"
20
+ },
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/balmjs/balm.git",
24
+ "directory": "packages/balm-core"
25
+ },
26
+ "files": [
27
+ "dist",
28
+ "CHANGELOG.md"
29
+ ],
6
30
  "main": "./dist/index.cjs",
7
31
  "module": "./dist/index.js",
8
32
  "types": "./dist/index.d.ts",
@@ -14,23 +38,33 @@
14
38
  }
15
39
  },
16
40
  "dependencies": {
41
+ "@babel/core": "^7.29.7",
42
+ "@babel/plugin-transform-runtime": "^7.26.0",
43
+ "@babel/preset-env": "^7.26.0",
44
+ "@babel/runtime": "^7.26.0",
17
45
  "archiver": "^7.0.1",
18
46
  "autoprefixer": "^10.4.20",
47
+ "babel-loader": "^9.2.1",
19
48
  "connect": "^3.7.0",
49
+ "css-loader": "^7.1.5",
20
50
  "cssnano": "^7.0.6",
21
51
  "esbuild": "^0.25.0",
22
52
  "fast-glob": "^3.3.3",
53
+ "html-loader": "^5.1.0",
23
54
  "html-minifier-terser": "^7.2.0",
24
55
  "http-proxy-middleware": "^3.0.3",
25
56
  "less": "^4.2.2",
57
+ "mini-css-extract-plugin": "^2.10.2",
26
58
  "picocolors": "^1.1.1",
27
59
  "picomatch": "^4.0.2",
28
60
  "postcss": "^8.5.3",
61
+ "postcss-loader": "^8.2.1",
29
62
  "postcss-preset-env": "^10.1.4",
30
63
  "rollup": "^4.34.8",
31
64
  "sass": "^1.85.0",
32
65
  "serve-static": "^1.16.2",
33
66
  "ssh2": "^1.16.0",
67
+ "style-loader": "^4.0.0",
34
68
  "terser": "^5.39.0",
35
69
  "webpack": "^5.98.0",
36
70
  "workbox-build": "^7.3.0",
@@ -53,6 +87,9 @@
53
87
  "engines": {
54
88
  "node": ">=18.18.0"
55
89
  },
90
+ "publishConfig": {
91
+ "access": "public"
92
+ },
56
93
  "scripts": {
57
94
  "build": "tsup",
58
95
  "dev": "tsup --watch"
package/src/balm.ts DELETED
@@ -1,107 +0,0 @@
1
- import { BalmConfig, BalmCustomConfig, BundlerType } from './types/index.js';
2
- import { resolveConfig } from './config/index.js';
3
- import { TaskDAG } from './runner/dag.js';
4
- import { BalmHooks } from './hooks/index.js';
5
- import { CleanTask } from './tasks/clean.js';
6
- import { StyleTask } from './tasks/style.js';
7
- import { ScriptTask } from './tasks/script.js';
8
- import { HtmlTask } from './tasks/html.js';
9
- import { CacheTask } from './tasks/cache.js';
10
- import { PwaTask } from './tasks/pwa.js';
11
- import { ServerTask } from './tasks/server.js';
12
- import { StaticTask } from './tasks/static.js';
13
- import { logger } from './utilities/logger.js';
14
-
15
- export class Balm {
16
- private _config: BalmConfig;
17
- private dag = new TaskDAG();
18
- beforeTask?: () => Promise<void> | void;
19
- afterTask?: () => Promise<void> | void;
20
- readonly Bundler = BundlerType;
21
-
22
- constructor() {
23
- this._config = resolveConfig();
24
- }
25
-
26
- get config(): BalmConfig {
27
- return this._config;
28
- }
29
- set config(customConfig: BalmCustomConfig) {
30
- this._config = resolveConfig(customConfig);
31
- if (this._config.logs?.level !== undefined) {
32
- logger.level = this._config.logs.level;
33
- }
34
- }
35
-
36
- async go(recipe?: (mix: BalmHooks) => void): Promise<void> {
37
- const endTimer = logger.time('Build');
38
- const taskSequence: string[] = [];
39
-
40
- // Register built-in tasks
41
- this.dag.registerTask(new CleanTask());
42
- this.dag.registerTask(new StyleTask());
43
- this.dag.registerTask(new ScriptTask());
44
- this.dag.registerTask(new StaticTask());
45
- this.dag.registerTask(new HtmlTask());
46
- this.dag.registerTask(new CacheTask());
47
- this.dag.registerTask(new PwaTask());
48
- this.dag.registerTask(new ServerTask());
49
-
50
- // Run recipe hooks
51
- if (typeof recipe === 'function') {
52
- const hooks = new BalmHooks(this.dag, this._config);
53
- recipe(hooks);
54
- }
55
-
56
- try {
57
- if (this.beforeTask) {
58
- await this.beforeTask();
59
- }
60
-
61
- if (this._config.useDefaults) {
62
- await this.dag.runSeries(
63
- ['clean', 'style', 'script', 'static', 'html'],
64
- this._config
65
- );
66
-
67
- if (this._config.env.isProd) {
68
- if (this._config.assets.cache) {
69
- await this.dag.executeTask('cache', this._config);
70
- }
71
- if (this._config.pwa.enabled) {
72
- await this.dag.executeTask('pwa', this._config);
73
- }
74
- }
75
- }
76
-
77
- // Execute recipe tasks
78
- for (let i = 1; ; i++) {
79
- const recipeName = `recipe:${i}`;
80
- if (!this.dag.hasTask(recipeName)) break;
81
- await this.dag.executeTask(recipeName, this._config);
82
- }
83
-
84
- if (this._config.useDefaults && !this._config.env.isProd) {
85
- await this.dag.executeTask('serve', this._config);
86
- }
87
-
88
- if (this.afterTask) {
89
- await this.afterTask();
90
- }
91
-
92
- endTimer();
93
- } catch (err: any) {
94
- logger.error('build', `Build failed: ${err?.message || err}`);
95
- throw err;
96
- }
97
- }
98
-
99
- reset(): void {
100
- this.dag.clear();
101
- this.beforeTask = undefined;
102
- this.afterTask = undefined;
103
- this._config = resolveConfig();
104
- }
105
- }
106
-
107
- export const balm = new Balm();
@@ -1,48 +0,0 @@
1
- import * as esbuild from 'esbuild';
2
- import path from 'node:path';
3
- import { BalmConfig } from '../types/index.js';
4
- import { logger } from '../utilities/logger.js';
5
- import { resolveDefaultEntry } from '../utilities/file.js';
6
-
7
- export async function runEsbuild(
8
- config: BalmConfig,
9
- customOptions: esbuild.BuildOptions = {}
10
- ): Promise<esbuild.BuildResult> {
11
- const isProd = config.env.isProd;
12
-
13
- let entryPoints = customOptions.entryPoints || config.scripts.entry;
14
- if (!entryPoints) {
15
- entryPoints = [resolveDefaultEntry(config.src.js)];
16
- }
17
-
18
- const defaultOptions: esbuild.BuildOptions = {
19
- entryPoints: (Array.isArray(entryPoints)
20
- ? entryPoints
21
- : typeof entryPoints === 'string'
22
- ? [entryPoints]
23
- : entryPoints) as any,
24
- absWorkingDir: config.workspace,
25
- bundle: true,
26
- outdir: config.dest.js,
27
- alias: {
28
- ...config.alias,
29
- ...config.scripts.alias
30
- },
31
- minify: isProd || config.scripts.minify,
32
- sourcemap: !isProd,
33
- target:
34
- config.scripts.target && config.scripts.target !== 'web'
35
- ? (config.scripts.target as string)
36
- : 'es2020',
37
- format: 'esm',
38
- ...config.scripts.esbuildOptions,
39
- ...customOptions
40
- };
41
-
42
- try {
43
- return await esbuild.build(defaultOptions);
44
- } catch (err: any) {
45
- logger.error('esbuild', err.message || err);
46
- throw err;
47
- }
48
- }
@@ -1,3 +0,0 @@
1
- export * from './webpack.js';
2
- export * from './rollup.js';
3
- export * from './esbuild.js';
@@ -1,46 +0,0 @@
1
- import { rollup, RollupOptions, OutputOptions } from 'rollup';
2
- import path from 'node:path';
3
- import { BalmConfig } from '../types/index.js';
4
- import { logger } from '../utilities/logger.js';
5
- import { resolveDefaultEntry } from '../utilities/file.js';
6
-
7
- export async function runRollup(
8
- config: BalmConfig,
9
- customInputOptions: RollupOptions = {},
10
- customOutputOptions: OutputOptions = {}
11
- ): Promise<void> {
12
- const isProd = config.env.isProd;
13
-
14
- let input = customInputOptions.input || config.scripts.entry;
15
- if (!input) {
16
- input = resolveDefaultEntry(config.src.js);
17
- }
18
-
19
- const inputOptions: RollupOptions = {
20
- ...config.scripts.rollupOptions,
21
- ...customInputOptions,
22
- input: (customInputOptions.input || input) as any
23
- };
24
-
25
- const outputOptions: OutputOptions = customOutputOptions.file
26
- ? {
27
- format: 'es',
28
- sourcemap: !isProd,
29
- ...customOutputOptions
30
- }
31
- : {
32
- dir: config.dest.js,
33
- format: 'es',
34
- sourcemap: !isProd,
35
- ...customOutputOptions
36
- };
37
-
38
- try {
39
- const bundle = await rollup(inputOptions);
40
- await bundle.write(outputOptions);
41
- await bundle.close();
42
- } catch (err: any) {
43
- logger.error('rollup', err.message || err);
44
- throw err;
45
- }
46
- }
@@ -1,125 +0,0 @@
1
- import webpack, { Configuration } from 'webpack';
2
- import path from 'node:path';
3
- import { BalmConfig } from '../types/index.js';
4
- import { logger } from '../utilities/logger.js';
5
- import { resolveDefaultEntry } from '../utilities/file.js';
6
-
7
- export async function runWebpack(
8
- config: BalmConfig,
9
- customOptions: Configuration = {}
10
- ): Promise<webpack.Stats | undefined> {
11
- const isProd = config.env.isProd;
12
-
13
- let entry = customOptions.entry || config.scripts.entry;
14
- if (!entry) {
15
- entry = resolveDefaultEntry(config.src.js);
16
- }
17
-
18
- const rawOutputPath = customOptions.output?.path;
19
- const isCustomOutput = Boolean(rawOutputPath);
20
- const outputPath = isCustomOutput
21
- ? path.isAbsolute(rawOutputPath as string)
22
- ? (rawOutputPath as string)
23
- : path.resolve(config.workspace, rawOutputPath as string)
24
- : config.dest.base;
25
-
26
- const jsDir = isCustomOutput ? '' : isProd ? config.paths.target.js : config.paths.tmp.js;
27
- const imgDir = isProd ? config.paths.target.img : config.paths.tmp.img;
28
- const fontDir = isProd ? config.paths.target.font : config.paths.tmp.font;
29
-
30
- const defaultWebpackConfig: Configuration = {
31
- mode: isProd ? 'production' : 'development',
32
- context: config.workspace,
33
- entry,
34
- output: {
35
- path: outputPath,
36
- filename: isCustomOutput
37
- ? '[name].js'
38
- : isProd && config.assets.cache
39
- ? `${jsDir}/[name].[contenthash:8].js`
40
- : `${jsDir}/[name].js`,
41
- chunkFilename: isCustomOutput
42
- ? 'chunk/[name].js'
43
- : isProd && config.assets.cache
44
- ? `${jsDir}/chunk/[name].[chunkhash:8].js`
45
- : `${jsDir}/chunk/[name].js`,
46
- publicPath: config.assets.virtualDir ? `/${config.assets.virtualDir}/` : '/',
47
- ...(config.scripts.library ? { library: config.scripts.library as any } : {})
48
- },
49
- target: config.scripts.target || 'web',
50
- externals: config.scripts.externals as any,
51
- plugins: [
52
- ...(config.scripts.plugins || [])
53
- ],
54
- resolve: {
55
- extensions: [
56
- '.wasm',
57
- '.mjs',
58
- '.js',
59
- '.jsx',
60
- '.ts',
61
- '.tsx',
62
- '.vue',
63
- '.json',
64
- ...(config.scripts.extensions || [])
65
- ],
66
- alias: {
67
- ...config.alias,
68
- ...config.scripts.alias
69
- }
70
- },
71
- module: {
72
- rules: [
73
- ...(config.scripts.loaders || []),
74
- {
75
- test: /\.(png|jpe?g|gif|svg|webp)$/i,
76
- type: 'asset/resource',
77
- generator: {
78
- filename: `${imgDir}/[name].[hash:8][ext]`
79
- }
80
- },
81
- {
82
- test: /\.(woff2?|eot|ttf|otf)$/i,
83
- type: 'asset/resource',
84
- generator: {
85
- filename: `${fontDir}/[name].[hash:8][ext]`
86
- }
87
- }
88
- ]
89
- },
90
- optimization: {
91
- minimize: isProd || config.scripts.minify
92
- },
93
- devtool: isProd ? false : 'eval-cheap-module-source-map'
94
- };
95
-
96
- const webpackConfig: Configuration = {
97
- ...defaultWebpackConfig,
98
- ...config.scripts.webpackOptions,
99
- ...customOptions,
100
- output: {
101
- ...defaultWebpackConfig.output,
102
- ...config.scripts.webpackOptions?.output,
103
- ...customOptions?.output,
104
- path: outputPath
105
- }
106
- };
107
-
108
- return new Promise((resolve, reject) => {
109
- const compiler = webpack(webpackConfig);
110
- compiler.run((err, stats) => {
111
- if (err) {
112
- logger.error('webpack', err.stack || err);
113
- return reject(err);
114
- }
115
-
116
- if (stats?.hasErrors()) {
117
- const info = stats.toJson();
118
- logger.error('webpack', info.errors?.map((e) => e.message).join('\n'));
119
- return reject(new Error('Webpack compilation errors'));
120
- }
121
-
122
- resolve(stats);
123
- });
124
- });
125
- }
@@ -1,12 +0,0 @@
1
- export const ASSETS_TYPES = ['css', 'js', 'img', 'font', 'media'];
2
- export const PUBLIC_URL = '%PUBLIC_URL%';
3
- export const CHUNK = { dir: 'chunk' };
4
- export const ASSET = { dir: 'asset' };
5
-
6
- export const ASSET_EXT = {
7
- styles: ['css', 'scss', 'sass', 'less'],
8
- scripts: ['js', 'mjs', 'cjs', 'ts', 'mts', 'cts', 'jsx', 'tsx'],
9
- images: ['png', 'jpg', 'jpeg', 'gif', 'svg', 'webp', 'ico'],
10
- fonts: ['woff', 'woff2', 'ttf', 'eot', 'otf'],
11
- media: ['mp4', 'webm', 'ogg', 'mp3', 'wav', 'flac', 'aac']
12
- };
@@ -1,212 +0,0 @@
1
- import path from 'node:path';
2
- import { BalmConfig, BundlerType } from '../types/index.js';
3
-
4
- export function createDefaultConfig(workspace = process.cwd()): BalmConfig {
5
- const isProd = process.env.NODE_ENV === 'production';
6
- const isDev = !isProd;
7
- const isTest = process.env.NODE_ENV === 'test';
8
-
9
- const roots = {
10
- source: 'src',
11
- tmp: '.tmp',
12
- target: 'dist'
13
- };
14
-
15
- const paths = {
16
- source: {
17
- base: '',
18
- html: '',
19
- css: 'styles',
20
- js: 'scripts',
21
- img: 'images',
22
- font: 'fonts',
23
- media: 'media'
24
- },
25
- tmp: {
26
- base: '',
27
- css: 'css',
28
- js: 'js',
29
- img: 'img',
30
- font: 'fonts',
31
- media: 'media'
32
- },
33
- target: {
34
- base: '',
35
- css: 'css',
36
- js: 'js',
37
- img: 'img',
38
- font: 'font',
39
- media: 'media'
40
- }
41
- };
42
-
43
- const alias: Record<string, string> = {
44
- '@': path.join(workspace, roots.source)
45
- };
46
-
47
- const styles = {
48
- extname: 'scss',
49
- minify: false,
50
- atImportPaths: [],
51
- alias: {},
52
- options: {},
53
- sassOptions: {},
54
- lessOptions: {},
55
- postcssLoaderOptions: {},
56
- postcssPlugins: [],
57
- sprites: [],
58
- spriteOptions: {}
59
- };
60
-
61
- const scripts = {
62
- bundler: BundlerType.webpack,
63
- minify: false,
64
- minifyOptions: {},
65
- entry: '',
66
- target: 'web',
67
- library: '',
68
- libraryTarget: 'var',
69
- externals: {},
70
- injectHtml: false,
71
- htmlName: 'index.html',
72
- alias: {},
73
- plugins: [],
74
- loaders: [],
75
- defaultLoaders: {
76
- html: true,
77
- css: true,
78
- js: true,
79
- url: true
80
- },
81
- options: {},
82
- esbuildOptions: {},
83
- rollupOptions: {},
84
- webpackOptions: {},
85
- useCache: false
86
- };
87
-
88
- const html = {
89
- options: {
90
- collapseWhitespace: true,
91
- minifyCSS: true,
92
- minifyJS: {
93
- compress: {
94
- drop_console: true
95
- }
96
- },
97
- processConditionalComments: true,
98
- removeComments: true,
99
- removeEmptyAttributes: true,
100
- removeScriptTypeAttributes: true,
101
- removeStyleLinkTypeAttributes: true
102
- },
103
- analytics: undefined
104
- };
105
-
106
- const assets = {
107
- root: 'assets',
108
- mainDir: 'public',
109
- subDir: '',
110
- buildDir: 'build',
111
- virtualDir: '',
112
- cache: false,
113
- options: {
114
- fileNameManifest: 'rev-manifest.json',
115
- dontRenameFile: ['.html'],
116
- dontUpdateReference: []
117
- },
118
- includes: [],
119
- excludes: []
120
- };
121
-
122
- const server = {
123
- host: null,
124
- port: 3000,
125
- open: true,
126
- proxy: false,
127
- proxyOptions: false,
128
- historyOptions: false,
129
- serveStatic: [],
130
- useHMR: false,
131
- options: {}
132
- };
133
-
134
- const pwa = {
135
- enabled: false,
136
- mode: 'generateSW' as const,
137
- version: '',
138
- manifest: 'manifest.json',
139
- workboxSw: 'node_modules/workbox-sw/build/workbox-sw.js',
140
- swSrcFilename: 'service-worker.js',
141
- swDestFilename: 'sw.js',
142
- options: {}
143
- };
144
-
145
- const ftp = {
146
- options: {},
147
- watchFiles: []
148
- };
149
-
150
- const images = {
151
- plugins: []
152
- };
153
-
154
- const env = {
155
- isProd,
156
- isDev,
157
- isTest,
158
- inFrontend: true,
159
- inSSR: false,
160
- inDesktopApp: false,
161
- isMP: false
162
- };
163
-
164
- const src = {
165
- base: path.join(workspace, roots.source),
166
- html: path.join(workspace, roots.source, paths.source.html),
167
- css: path.join(workspace, roots.source, paths.source.css),
168
- js: path.join(workspace, roots.source, paths.source.js),
169
- img: path.join(workspace, roots.source, paths.source.img),
170
- font: path.join(workspace, roots.source, paths.source.font),
171
- media: path.join(workspace, roots.source, paths.source.media)
172
- };
173
-
174
- const targetBase = path.join(workspace, isProd ? roots.target : roots.tmp);
175
- const dest = {
176
- base: targetBase,
177
- html: targetBase,
178
- css: path.join(targetBase, isProd ? paths.target.css : paths.tmp.css),
179
- js: path.join(targetBase, isProd ? paths.target.js : paths.tmp.js),
180
- img: path.join(targetBase, isProd ? paths.target.img : paths.tmp.img),
181
- font: path.join(targetBase, isProd ? paths.target.font : paths.tmp.font),
182
- media: path.join(targetBase, isProd ? paths.target.media : paths.tmp.media),
183
- static: path.join(targetBase, assets.virtualDir, assets.subDir)
184
- };
185
-
186
- return {
187
- workspace,
188
- workspaces: {
189
- local: workspace,
190
- global: path.resolve(workspace, '..')
191
- },
192
- alias,
193
- env,
194
- inFrontend: true,
195
- useDefaults: true,
196
- roots,
197
- paths,
198
- styles,
199
- scripts,
200
- html,
201
- assets,
202
- server,
203
- pwa,
204
- ftp,
205
- images,
206
- logs: {
207
- level: 1
208
- },
209
- src,
210
- dest
211
- };
212
- }