orga-build 0.6.0 → 0.6.2
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/cli.js +7 -2
- package/lib/__tests__/build.test.js +29 -0
- package/lib/build.d.ts +2 -1
- package/lib/build.d.ts.map +1 -1
- package/lib/build.js +4 -4
- package/lib/config.d.ts +5 -2
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js +7 -2
- package/lib/serve.d.ts +2 -1
- package/lib/serve.d.ts.map +1 -1
- package/lib/serve.js +3 -2
- package/lib/vite.d.ts +1 -0
- package/lib/vite.d.ts.map +1 -1
- package/lib/vite.js +1 -1
- package/package.json +1 -1
- package/lib/client.jsx +0 -12
package/cli.js
CHANGED
|
@@ -16,6 +16,11 @@ const { positionals } = parseArgs({
|
|
|
16
16
|
allowPositionals: true
|
|
17
17
|
})
|
|
18
18
|
|
|
19
|
-
const config = await loadConfig(
|
|
19
|
+
const { config, projectRoot } = await loadConfig(
|
|
20
|
+
'orga.config.js',
|
|
21
|
+
'orga.config.mjs'
|
|
22
|
+
)
|
|
20
23
|
|
|
21
|
-
await (positionals.includes('dev')
|
|
24
|
+
await (positionals.includes('dev')
|
|
25
|
+
? serve(config, 3000, projectRoot)
|
|
26
|
+
: build(config, projectRoot))
|
|
@@ -29,6 +29,10 @@ Here's [[file:more.org][another page]].
|
|
|
29
29
|
)
|
|
30
30
|
await fs.writeFile(path.join(fixtureDir, 'docs', 'index.org'), 'Docs index page.')
|
|
31
31
|
await fs.writeFile(path.join(fixtureDir, 'more.org'), 'Another page.')
|
|
32
|
+
await fs.writeFile(
|
|
33
|
+
path.join(fixtureDir, 'style.css'),
|
|
34
|
+
'.global-style-marker { color: rgb(1, 2, 3); }'
|
|
35
|
+
)
|
|
32
36
|
})
|
|
33
37
|
|
|
34
38
|
after(async () => {
|
|
@@ -70,4 +74,29 @@ Here's [[file:more.org][another page]].
|
|
|
70
74
|
.catch(() => false)
|
|
71
75
|
assert.ok(assetsExists, 'assets directory should exist')
|
|
72
76
|
})
|
|
77
|
+
|
|
78
|
+
test('processes configured global styles through vite and injects built css', async () => {
|
|
79
|
+
await build({
|
|
80
|
+
root: fixtureDir,
|
|
81
|
+
outDir: outDir,
|
|
82
|
+
containerClass: [],
|
|
83
|
+
styles: ['/style.css'],
|
|
84
|
+
vitePlugins: [],
|
|
85
|
+
preBuild: [],
|
|
86
|
+
postBuild: []
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
const html = await fs.readFile(path.join(outDir, 'index.html'), 'utf-8')
|
|
90
|
+
assert.ok(!html.includes('href="/style.css"'), 'should not link raw source css path')
|
|
91
|
+
|
|
92
|
+
const cssHrefMatch = html.match(/href="\/(assets\/[^"]+\.css)"/)
|
|
93
|
+
assert.ok(cssHrefMatch, 'should link built css asset from assets with hashed name')
|
|
94
|
+
|
|
95
|
+
const builtCssPath = cssHrefMatch[1]
|
|
96
|
+
const builtCss = await fs.readFile(path.join(outDir, builtCssPath), 'utf-8')
|
|
97
|
+
assert.ok(
|
|
98
|
+
builtCss.includes('.global-style-marker'),
|
|
99
|
+
'built css should include configured global style content'
|
|
100
|
+
)
|
|
101
|
+
})
|
|
73
102
|
})
|
package/lib/build.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @param {import('./config.js').Config} config
|
|
3
|
+
* @param {string} [projectRoot]
|
|
3
4
|
*/
|
|
4
|
-
export function build({ outDir, root, containerClass, styles, vitePlugins }: import("./config.js").Config): Promise<void>;
|
|
5
|
+
export function build({ outDir, root, containerClass, styles, vitePlugins }: import("./config.js").Config, projectRoot?: string): Promise<void>;
|
|
5
6
|
export { alias };
|
|
6
7
|
import { alias } from './plugin.js';
|
|
7
8
|
//# sourceMappingURL=build.d.ts.map
|
package/lib/build.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["build.js"],"names":[],"mappings":"AAeA
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["build.js"],"names":[],"mappings":"AAeA;;;GAGG;AACH,6EAHW,OAAO,aAAa,EAAE,MAAM,gBAC5B,MAAM,iBAoJhB;;sBAhK4C,aAAa"}
|
package/lib/build.js
CHANGED
|
@@ -5,16 +5,17 @@ import { emptyDir, ensureDir, exists } from './fs.js'
|
|
|
5
5
|
import fs from 'fs/promises'
|
|
6
6
|
import { createOrgaBuildConfig, alias } from './plugin.js'
|
|
7
7
|
import { escapeHtml } from './util.js'
|
|
8
|
+
import { appEntryId } from './vite.js'
|
|
8
9
|
|
|
9
10
|
// Re-export alias for backwards compatibility
|
|
10
11
|
export { alias }
|
|
11
12
|
|
|
12
13
|
const ssrEntry = fileURLToPath(new URL('./ssr.jsx', import.meta.url))
|
|
13
|
-
const clientEntry = fileURLToPath(new URL('./client.jsx', import.meta.url))
|
|
14
14
|
const defaultIndexHtml = fileURLToPath(new URL('./index.html', import.meta.url))
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* @param {import('./config.js').Config} config
|
|
18
|
+
* @param {string} [projectRoot]
|
|
18
19
|
*/
|
|
19
20
|
export async function build({
|
|
20
21
|
outDir,
|
|
@@ -22,7 +23,7 @@ export async function build({
|
|
|
22
23
|
containerClass,
|
|
23
24
|
styles = [],
|
|
24
25
|
vitePlugins = []
|
|
25
|
-
}) {
|
|
26
|
+
}, projectRoot = process.cwd()) {
|
|
26
27
|
await emptyDir(outDir)
|
|
27
28
|
const ssrOutDir = path.join(outDir, '.ssr')
|
|
28
29
|
const clientOutDir = outDir
|
|
@@ -65,7 +66,7 @@ export async function build({
|
|
|
65
66
|
emptyOutDir: false,
|
|
66
67
|
assetsDir: 'assets',
|
|
67
68
|
rollupOptions: {
|
|
68
|
-
input:
|
|
69
|
+
input: appEntryId,
|
|
69
70
|
preserveEntrySignatures: 'allow-extension'
|
|
70
71
|
}
|
|
71
72
|
}
|
|
@@ -103,7 +104,6 @@ export async function build({
|
|
|
103
104
|
|
|
104
105
|
/* --- get html template, inject entry js and css --- */
|
|
105
106
|
// Check for user's index.html in project root, otherwise use default
|
|
106
|
-
const projectRoot = process.cwd()
|
|
107
107
|
const userIndexPath = path.join(projectRoot, 'index.html')
|
|
108
108
|
const indexHtmlPath = (await exists(userIndexPath)) ? userIndexPath : defaultIndexHtml
|
|
109
109
|
const template = await fs.readFile(indexHtmlPath, { encoding: 'utf-8' })
|
package/lib/config.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @param {string[]} files
|
|
3
|
-
* @returns {Promise<Config>}
|
|
3
|
+
* @returns {Promise<{ config: Config, projectRoot: string }>}
|
|
4
4
|
*/
|
|
5
|
-
export function loadConfig(...files: string[]): Promise<
|
|
5
|
+
export function loadConfig(...files: string[]): Promise<{
|
|
6
|
+
config: Config;
|
|
7
|
+
projectRoot: string;
|
|
8
|
+
}>;
|
|
6
9
|
export type Config = {
|
|
7
10
|
outDir: string;
|
|
8
11
|
root: string;
|
package/lib/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["config.js"],"names":[],"mappings":"AAyBA;;;GAGG;AACH,qCAHW,MAAM,EAAE,GACN,OAAO,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["config.js"],"names":[],"mappings":"AAyBA;;;GAGG;AACH,qCAHW,MAAM,EAAE,GACN,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,CAAC,CA6C5D;;YAnEa,MAAM;UACN,MAAM;cACN,MAAM,EAAE;eACR,MAAM,EAAE;;;;iBACR,OAAO,MAAM,EAAE,YAAY,EAAE;oBAC7B,MAAM,EAAE,GAAC,MAAM;;;;aACf,MAAM,EAAE"}
|
package/lib/config.js
CHANGED
|
@@ -25,7 +25,7 @@ const defaultConfig = {
|
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* @param {string[]} files
|
|
28
|
-
* @returns {Promise<Config>}
|
|
28
|
+
* @returns {Promise<{ config: Config, projectRoot: string }>}
|
|
29
29
|
*/
|
|
30
30
|
export async function loadConfig(...files) {
|
|
31
31
|
const cwd = process.cwd()
|
|
@@ -37,6 +37,7 @@ export async function loadConfig(...files) {
|
|
|
37
37
|
path.isAbsolute(value) ? value : path.resolve(cwd, value)
|
|
38
38
|
|
|
39
39
|
let result = { ...defaultConfig }
|
|
40
|
+
let configPath = null
|
|
40
41
|
|
|
41
42
|
for (const file of files) {
|
|
42
43
|
const filePath = path.join(cwd, file)
|
|
@@ -53,6 +54,7 @@ export async function loadConfig(...files) {
|
|
|
53
54
|
// Support both default export (recommended) and named exports
|
|
54
55
|
const config = module.default || module
|
|
55
56
|
result = { ...defaultConfig, ...config }
|
|
57
|
+
configPath = filePath
|
|
56
58
|
break
|
|
57
59
|
} catch (err) {
|
|
58
60
|
// Config file exists but has errors
|
|
@@ -64,5 +66,8 @@ export async function loadConfig(...files) {
|
|
|
64
66
|
result.outDir = resolveConfigPath(result.outDir)
|
|
65
67
|
const styles = result.styles
|
|
66
68
|
result.styles = Array.isArray(styles) ? styles.filter((v) => typeof v === 'string') : []
|
|
67
|
-
return
|
|
69
|
+
return {
|
|
70
|
+
config: result,
|
|
71
|
+
projectRoot: configPath ? path.dirname(configPath) : cwd
|
|
72
|
+
}
|
|
68
73
|
}
|
package/lib/serve.d.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @param {import('./config.js').Config} config
|
|
5
5
|
* @param {number} [port]
|
|
6
|
+
* @param {string} [projectRoot]
|
|
6
7
|
*/
|
|
7
|
-
export function serve(config: import("./config.js").Config, port?: number): Promise<void>;
|
|
8
|
+
export function serve(config: import("./config.js").Config, port?: number, projectRoot?: string): Promise<void>;
|
|
8
9
|
//# sourceMappingURL=serve.d.ts.map
|
package/lib/serve.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["serve.js"],"names":[],"mappings":"AAIA
|
|
1
|
+
{"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["serve.js"],"names":[],"mappings":"AAIA;;;;;;GAMG;AACH,8BAJW,OAAO,aAAa,EAAE,MAAM,SAC5B,MAAM,gBACN,MAAM,iBAsChB"}
|
package/lib/serve.js
CHANGED
|
@@ -7,8 +7,9 @@ import { createOrgaBuildConfig, alias } from './plugin.js'
|
|
|
7
7
|
*
|
|
8
8
|
* @param {import('./config.js').Config} config
|
|
9
9
|
* @param {number} [port]
|
|
10
|
+
* @param {string} [projectRoot]
|
|
10
11
|
*/
|
|
11
|
-
export async function serve(config, port = 3000) {
|
|
12
|
+
export async function serve(config, port = 3000, projectRoot = process.cwd()) {
|
|
12
13
|
const { plugins } = createOrgaBuildConfig({
|
|
13
14
|
root: config.root,
|
|
14
15
|
outDir: config.outDir,
|
|
@@ -16,7 +17,7 @@ export async function serve(config, port = 3000) {
|
|
|
16
17
|
styles: config.styles ?? [],
|
|
17
18
|
vitePlugins: config.vitePlugins,
|
|
18
19
|
includeFallbackHtml: true,
|
|
19
|
-
projectRoot
|
|
20
|
+
projectRoot
|
|
20
21
|
})
|
|
21
22
|
|
|
22
23
|
const server = await createServer({
|
package/lib/vite.d.ts
CHANGED
package/lib/vite.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["vite.js"],"names":[],"mappings":"AASA;;;;;;GAMG;AACH,uDALG;IAAwB,GAAG,EAAnB,MAAM;IACW,MAAM;IACJ,MAAM;CACjC,GAAU,OAAO,MAAM,EAAE,MAAM,CA8JjC"}
|
|
1
|
+
{"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["vite.js"],"names":[],"mappings":"AASA;;;;;;GAMG;AACH,uDALG;IAAwB,GAAG,EAAnB,MAAM;IACW,MAAM;IACJ,MAAM;CACjC,GAAU,OAAO,MAAM,EAAE,MAAM,CA8JjC;AAvKD,gDAAuD"}
|
package/lib/vite.js
CHANGED
|
@@ -3,7 +3,7 @@ import path from 'node:path'
|
|
|
3
3
|
|
|
4
4
|
const magicModulePrefix = '/@orga-build/'
|
|
5
5
|
const pagesModuleId = magicModulePrefix + 'pages'
|
|
6
|
-
const appEntryId = `${magicModulePrefix}main.js`
|
|
6
|
+
export const appEntryId = `${magicModulePrefix}main.js`
|
|
7
7
|
const contentModuleId = 'orga-build:content'
|
|
8
8
|
const contentModuleIdResolved = '\0' + contentModuleId
|
|
9
9
|
|
package/package.json
CHANGED
package/lib/client.jsx
DELETED