rebuildjs 0.9.2 → 0.10.1

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.
package/browser/index.js CHANGED
@@ -2,7 +2,7 @@ import { file_exists_ } from '@ctx-core/fs'
2
2
  import { nullish__none_, tup } from 'ctx-core/function'
3
3
  import { be_memo_pair_, be_sig_triple_ } from 'ctx-core/rmemo'
4
4
  import { readFile } from 'fs/promises'
5
- import { join } from 'path'
5
+ import { join, relative } from 'path'
6
6
  import { browser_path_, browser__relative_path_ } from '../app/index.js'
7
7
  import { app_ctx__be_config, middleware_ctx__be_config } from '../ctx/index.js'
8
8
  import { server__input_path_ } from '../server/index.js'
@@ -60,6 +60,6 @@ export const [
60
60
  browser__script_,
61
61
  ] = be_memo_pair_(ctx=>
62
62
  nullish__none_([browser__output__relative_path_(ctx), browser__relative_path_(ctx)],
63
- (browser__output_path, browser_relative_path)=>
64
- browser__output_path.replace(browser_relative_path, '')),
63
+ (browser__output__relative_path, browser__relative_path)=>
64
+ relative(browser__relative_path, browser__output__relative_path)),
65
65
  { ...middleware_ctx__be_config, id: 'browser__script' })
package/build/index.d.ts CHANGED
@@ -1,5 +1,9 @@
1
1
  import type { BuildOptions, Plugin } from 'esbuild'
2
- export declare function server__build(config?:Partial<BuildOptions>):Promise<void>
2
+ export declare function server__build(config?:rebuildjs__build_config_T):Promise<void>
3
3
  export declare function server__external_(config?:Partial<BuildOptions>):Promise<string[]>
4
- export declare function browser__build(config?:Partial<BuildOptions>):Promise<void>
5
- export declare function rebuildjs_plugin_():Plugin
4
+ export declare function browser__build(config?:rebuildjs__build_config_T):Promise<void>
5
+ export declare function rebuildjs__plugin_():Plugin
6
+ export type rebuildjs__build_config_T = Partial<BuildOptions>&{ rebuildjs?: rebuildjs__plugin_config_T }
7
+ export type rebuildjs__plugin_config_T = {
8
+ watch?:boolean
9
+ }
package/build/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ /// <reference types="./index.d.ts" />
1
2
  /** @typedef {import('esbuild').BuildOptions}BuildOptions */
2
3
  /** @typedef {import('esbuild').Plugin}Plugin */
3
4
  import { writeFile } from '@ctx-core/monorepo'
@@ -16,10 +17,11 @@ import {
16
17
  server__metafile__set
17
18
  } from '../server/index.js'
18
19
  /**
19
- * @param {Partial<BuildOptions>}config
20
+ * @param {rebuildjs__build_config_T}[config]
20
21
  * @returns {Promise<void>}
21
22
  */
22
- export async function server__build(config = {}) {
23
+ export async function server__build(config) {
24
+ const { rebuildjs, ...esbuild__config } = config ?? {}
23
25
  await rm(server_path_(app_ctx), { recursive: true, force: true })
24
26
  const path_a = await new fdir()
25
27
  .glob('**/*.server.{ts,js,tsx,jsx}')
@@ -27,11 +29,11 @@ export async function server__build(config = {}) {
27
29
  .crawl(app_path_(app_ctx))
28
30
  .withPromise()
29
31
  /** @type {string[]} */
30
- const entryPoints = config?.entryPoints ?? []
32
+ const entryPoints = esbuild__config?.entryPoints ?? []
31
33
  for (const path of path_a) {
32
34
  entryPoints.push(path)
33
35
  }
34
- const plugins = [rebuildjs_plugin_(), ...(config.plugins || [])]
36
+ const plugins = [rebuildjs__plugin_(), ...(esbuild__config.plugins || [])]
35
37
  const esbuild_config = {
36
38
  entryNames: '[name]-[hash]',
37
39
  assetNames: '[name]-[hash]',
@@ -40,17 +42,17 @@ export async function server__build(config = {}) {
40
42
  treeShaking: true,
41
43
  minify: is_prod_(app_ctx),
42
44
  sourcemap: 'external',
43
- ...config,
45
+ ...esbuild__config,
44
46
  entryPoints,
45
47
  format: 'esm',
46
48
  platform: 'node',
47
49
  absWorkingDir: cwd_(app_ctx),
48
50
  metafile: true,
49
51
  outdir: server_path_(app_ctx),
50
- external: server__external_(config),
52
+ external: server__external_(esbuild__config),
51
53
  plugins,
52
54
  }
53
- if (is_prod_(app_ctx)) {
55
+ if (rebuildjs?.watch ?? is_prod_(app_ctx)) {
54
56
  await build(esbuild_config)
55
57
  } else {
56
58
  const esbuild_ctx = await context(esbuild_config)
@@ -59,7 +61,7 @@ export async function server__build(config = {}) {
59
61
  }
60
62
  }
61
63
  /**
62
- * @param {Partial<BuildOptions>}config
64
+ * @param {rebuildjs__build_config_T}[config]
63
65
  * @returns {Promise<string[]>}
64
66
  */
65
67
  export function server__external_(config) {
@@ -70,7 +72,8 @@ export function server__external_(config) {
70
72
  * @returns {Promise<void>}
71
73
  * @private
72
74
  */
73
- export async function browser__build(config = {}) {
75
+ export async function browser__build(config) {
76
+ const { rebuildjs, ...esbuild__config } = config ?? {}
74
77
  await rm(browser_path_(app_ctx), { recursive: true, force: true })
75
78
  await mkdir(browser_path_(app_ctx), { recursive: true })
76
79
  const path_a = await new fdir()
@@ -79,11 +82,11 @@ export async function browser__build(config = {}) {
79
82
  .crawl(app_path_(app_ctx))
80
83
  .withPromise()
81
84
  /** @type {string[]} */
82
- const entryPoints = config?.entryPoints ?? []
85
+ const entryPoints = esbuild__config?.entryPoints ?? []
83
86
  for (const path of path_a) {
84
87
  entryPoints.push(path)
85
88
  }
86
- const plugins = [rebuildjs_plugin_(), ...(config.plugins || [])]
89
+ const plugins = [rebuildjs__plugin_(), ...(esbuild__config.plugins || [])]
87
90
  /** @type {BuildOptions} */
88
91
  const esbuild_config = {
89
92
  entryNames: '[name]-[hash]',
@@ -94,7 +97,7 @@ export async function browser__build(config = {}) {
94
97
  treeShaking: true,
95
98
  minify: is_prod_(app_ctx),
96
99
  sourcemap: 'external',
97
- ...config,
100
+ ...esbuild__config,
98
101
  entryPoints,
99
102
  format: 'esm',
100
103
  platform: 'browser',
@@ -103,7 +106,7 @@ export async function browser__build(config = {}) {
103
106
  outdir: browser_path_(app_ctx),
104
107
  plugins,
105
108
  }
106
- if (is_prod_(app_ctx)) {
109
+ if (rebuildjs?.watch ?? is_prod_(app_ctx)) {
107
110
  await build(esbuild_config)
108
111
  } else {
109
112
  const esbuild_ctx = await context(esbuild_config)
@@ -116,9 +119,9 @@ export async function browser__build(config = {}) {
116
119
  * @returns {Plugin}
117
120
  * @private
118
121
  */
119
- export function rebuildjs_plugin_() {
122
+ export function rebuildjs__plugin_() {
120
123
  return {
121
- name: 'rebuildjs_plugin',
124
+ name: 'rebuildjs__plugin',
122
125
  setup(build) {
123
126
  build.onEnd(async result=>{
124
127
  if (result.metafile) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rebuildjs",
3
- "version": "0.9.2",
3
+ "version": "0.10.1",
4
4
  "description": "Reactive esbuild...simple hackable alternative to vite for Multi Page Apps",
5
5
  "keywords": [
6
6
  "reactive",
package/server/index.js CHANGED
@@ -2,7 +2,7 @@ import { file_exists_ } from '@ctx-core/fs'
2
2
  import { nullish__none_, tup } from 'ctx-core/function'
3
3
  import { be_lock_memosig_triple_, be_memo_pair_, be_sig_triple_ } from 'ctx-core/rmemo'
4
4
  import { readFile } from 'fs/promises'
5
- import { join } from 'path'
5
+ import { join, relative } from 'path'
6
6
  import { cwd_, server_path_ } from '../app/index.js'
7
7
  import { app_ctx__be_config, middleware_ctx__be_config } from '../ctx/index.js'
8
8
  export const [
@@ -68,5 +68,5 @@ export const [
68
68
  ] = be_memo_pair_(ctx=>
69
69
  nullish__none_([server__cssBundle_(ctx)],
70
70
  cssBundle=>
71
- cssBundle.replace(server_path_(ctx), '')),
71
+ relative(server_path_(ctx), cssBundle)),
72
72
  { ...middleware_ctx__be_config, id: 'server__css' })