Skip to content

Commit 90daac5

Browse files
authored
Merge pull request #657 from DanielXMoore/🐈.json
🐈🐈🐈
2 parents 355a24f + 330cb36 commit 90daac5

30 files changed

+326
-664
lines changed

build/build.sh

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,14 @@
22
set -euo pipefail
33

44
# normal files
5-
coffee build/esbuild.coffee
5+
civet --no-config build/esbuild.civet
66

77
# cli
88
BIN="dist/civet"
99
echo "#!/usr/bin/env node" | cat - dist/cli.js > "$BIN"
1010
chmod +x "$BIN"
1111
rm dist/cli.js
1212

13-
# esbuild-plugin
14-
./dist/civet --no-config --js -c source/esbuild-plugin.civet -o dist/esbuild-plugin.js
15-
16-
# esm loader
17-
./dist/civet --no-config --js -c source/esm.civet -o dist/esm.mjs
18-
1913
# babel plugin
2014
cp source/babel-plugin.mjs dist/babel-plugin.mjs
2115

build/coffee-esm.mjs

Lines changed: 0 additions & 47 deletions
This file was deleted.

build/esbuild.civet

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
"civet coffeeCompat"
2+
3+
esbuild = require "esbuild"
4+
heraPlugin = require "@danielx/hera/esbuild-plugin"
5+
# Need to use the packaged version because we may not have built our own yet
6+
civetPlugin = require "../node_modules/@danielx/civet/dist/esbuild-plugin.js"
7+
8+
watch = process.argv.includes '--watch'
9+
minify = false
10+
sourcemap = false
11+
12+
path = require "path"
13+
{access} = require "fs/promises"
14+
exists = (p) ->
15+
access(p)
16+
.then ->
17+
true
18+
.catch ->
19+
false
20+
extensionResolverPlugin = (extensions) ->
21+
name: "extension-resolve"
22+
setup: (build) ->
23+
# For relative requires that don't contain a '.'
24+
build.onResolve { filter: /\/[^.]*$/ }, (r) ->
25+
for extension in extensions
26+
{path: resolvePath, resolveDir} = r
27+
p = path.join(resolveDir, resolvePath + ".#{extension}")
28+
29+
# see if a .coffee file exists
30+
found = await exists(p)
31+
if found
32+
return path: p
33+
34+
return undefined
35+
36+
resolveExtensions = extensionResolverPlugin(["civet", "hera"])
37+
38+
# To get proper extension resolution for non-bundled files, we need to use
39+
# a plugin hack: https://github.com/evanw/esbuild/issues/622#issuecomment-769462611
40+
# set bundle: true, then rewrite .coffee -> .js and mark as external
41+
# Also marking everything else as external since we don't want to bundle anything
42+
rewriteCivetImports = {
43+
name: 'rewrite-civet',
44+
setup: (build) ->
45+
build.onResolve { filter: /.*/ }, (args) ->
46+
if (args.importer)
47+
path: args.path.replace(/\.civet$/, ".js")
48+
external: true
49+
}
50+
51+
# Files that need civet imports re-written
52+
# since they aren't actually bundled
53+
["cli", "config", "esbuild-plugin"].forEach (name) ->
54+
esbuild.build({
55+
entryPoints: ["source/#{name}.civet"]
56+
bundle: true
57+
platform: 'node'
58+
format: 'cjs'
59+
outfile: "dist/#{name}.js"
60+
plugins: [
61+
rewriteCivetImports
62+
civetPlugin()
63+
]
64+
}).catch -> process.exit 1
65+
66+
# esm needs to be a module for import.meta
67+
["esm"].forEach (name) ->
68+
esbuild.build({
69+
entryPoints: ["source/#{name}.civet"]
70+
bundle: true
71+
platform: 'node'
72+
format: 'esm'
73+
outfile: "dist/#{name}.mjs"
74+
plugins: [
75+
rewriteCivetImports
76+
civetPlugin()
77+
]
78+
}).catch -> process.exit 1
79+
80+
for esm in [false, true]
81+
esbuild.build({
82+
entryPoints: ['source/main.civet']
83+
bundle: true
84+
watch
85+
platform: 'node'
86+
format: if esm then 'esm' else 'cjs'
87+
outfile: "dist/main.#{if esm then 'mjs' else 'js'}"
88+
plugins: [
89+
resolveExtensions
90+
civetPlugin()
91+
heraPlugin
92+
]
93+
}).catch -> process.exit 1
94+
95+
esbuild.build({
96+
entryPoints: ['source/main.civet']
97+
globalName: "Civet"
98+
bundle: true
99+
sourcemap
100+
watch
101+
platform: 'browser'
102+
outfile: 'dist/browser.js'
103+
plugins: [
104+
resolveExtensions
105+
civetPlugin()
106+
heraPlugin
107+
]
108+
}).catch -> process.exit 1
109+
110+
esbuild.build({
111+
entryPoints: ['source/bun-civet.civet']
112+
bundle: false
113+
sourcemap
114+
minify
115+
watch
116+
platform: 'node'
117+
format: 'esm'
118+
target: "esNext"
119+
outfile: 'dist/bun-civet.mjs'
120+
plugins: [
121+
civetPlugin()
122+
]
123+
}).catch -> process.exit 1

build/esbuild.coffee

Lines changed: 0 additions & 120 deletions
This file was deleted.

build/hera-esm.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export async function resolve(specifier, context, defaultResolve) {
2020

2121
export async function load(url, context, next) {
2222
if (extensionsRegex.test(url)) {
23-
return next(url.replace(extensionsRegex, ".cjs"), {
23+
return next(url, {
2424
format: "commonjs"
2525
});
2626
}

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
"./esm": "./dist/esm.mjs",
1515
"./esbuild-plugin": "./dist/esbuild-plugin.js",
1616
"./register": "./register.js",
17-
"./config": "./dist/config.js",
1817
"./*": "./*",
1918
"./dist/*": "./dist/*"
2019
},
@@ -43,15 +42,14 @@
4342
"@cspotcode/source-map-support": "^0.8.1"
4443
},
4544
"devDependencies": {
45+
"@danielx/civet": "^0.6.26",
4646
"@danielx/hera": "^0.8.10",
4747
"@types/assert": "^1.5.6",
48-
"@types/coffeescript": "^2.5.2",
4948
"@types/mocha": "^9.1.1",
5049
"@types/node": "^18.7.8",
5150
"axios": "^1.2.2",
5251
"c8": "^7.12.0",
5352
"esbuild": "^0.14.49",
54-
"esbuild-coffeescript": "^2.1.0",
5553
"marked": "^4.2.4",
5654
"mocha": "^10.0.0",
5755
"prettier": "^2.8.1",
@@ -71,7 +69,10 @@
7169
"extension": [
7270
".civet",
7371
".coffee",
72+
".hera",
7473
".js",
74+
".mjs",
75+
".mts",
7576
".ts"
7677
],
7778
"include": [
@@ -85,9 +86,8 @@
8586
],
8687
"loader": [
8788
"ts-node/esm",
88-
"./build/coffee-esm.mjs",
8989
"./build/hera-esm.mjs",
90-
"./dist/esm.mjs"
90+
"./node_modules/@danielx/civet/dist/esm.mjs"
9191
],
9292
"reporter": "dot",
9393
"recursive": true,
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import {parse, compile, generate} from "./main"
2-
import {findConfig, loadConfig} from "./config"
1+
"civet coffeeCompat"
2+
3+
import {parse, compile, generate} from "./main.civet"
4+
import {findConfig, loadConfig} from "./config.civet"
35
{prune} = generate
46

57
version = -> require("../package.json").version
@@ -196,7 +198,7 @@ cli = ->
196198

197199
if options.config isnt false # --no-config
198200
options.config ?= await findConfig(process.cwd())
199-
201+
200202
if options.config
201203
options = {
202204
...(await loadConfig options.config),

0 commit comments

Comments
 (0)