Skip to content

Commit

Permalink
refactor(build): remove esbuild as much as possible
Browse files Browse the repository at this point in the history
  • Loading branch information
heapwolf committed Apr 25, 2024
1 parent 74db553 commit 25cc159
Show file tree
Hide file tree
Showing 21 changed files with 14,726 additions and 308,188 deletions.
38 changes: 9 additions & 29 deletions build.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,10 @@
#!/usr/bin/env node
import path from 'node:path'
import fs from 'node:fs/promises'

//
// Most newer modules don't need to be bundled. But the monaco
// and xterm packages rely on bundler-features heavily.
//
import esbuild from 'esbuild'

const __dirname = path.dirname(new URL(import.meta.url).pathname)

const cp = async (a, b) => fs.cp(
path.resolve(a),
path.join(b, path.basename(a)),
{ recursive: true, force: true }
)

async function copy (target) {
await cp('src/index.html', target)
await cp('src/vm.js', target)
await cp('src/preview.js', target)
await cp('src/worker.js', target)
await cp('icons/icon.png', target)
await cp('src/settings.json', target)
await cp('src/fonts', target)
await cp('src/lib', target)
await cp('src/pages', target)
await cp('src/css', target)
}

async function main (argv) {
const workerEntryPoints = [
'vs/language/json/json.worker.js',
Expand All @@ -37,25 +17,25 @@ async function main (argv) {
await esbuild.build({
entryPoints: workerEntryPoints.map((entry) => `node_modules/monaco-editor/esm/${entry}`),
bundle: true,
minify: false,
minify: true,
format: 'iife',
outbase: 'node_modules/monaco-editor/esm/',
outdir: 'src/lib'
})

const params = {
entryPoints: ['src/index.js'],
entryPoints: ['src/vendor.js'],
format: 'esm',
bundle: true,
minify: false,
minify: true,
sourcemap: false,
external: ['socket:*', 'node:*'],
loader: {
'.ttf': 'file'
}
}

const target = process.env.PREFIX

if (!target) {
console.log('This script should not be run directly. It will be run by the SSC command.')
process.exit(0)
Expand All @@ -65,8 +45,8 @@ async function main (argv) {
...params,
outdir: target
}

await esbuild.build(opts)
await copy(target)
}

main(process.argv.slice(2))
8 changes: 2 additions & 6 deletions importmap.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
"imports": {
"@socketsupply/tonic": "npm:@socketsupply/tonic",
"@socketsupply/components": "npm:@socketsupply/components",
"@socketsupply/components/*": "npm:@socketsupply/components/*",
"@socketsupply/indexed": "npm:@socketsupply/indexed",
"monaco-editor": "npm:monaco-editor",
"xterm": "npm:xterm",
"xterm-addon-fit": "npm:xterm-addon-fit",
"xterm-addon-search": "npm:xterm-addon-search"
"@socketsupply/components/dialog": "npm:@socketsupply/components/dialog",
"@socketsupply/indexed": "npm:@socketsupply/indexed"
}
}
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@
"type": "git"
},
"devDependencies": {
"@socketsupply/components": "^14.0.13",
"@socketsupply/indexed": "^1.0.3",
"@socketsupply/tonic": "^15.1.2",
"esbuild": "^0.20.0",
"monaco-editor": "^0.46.0",
"standard": "^17.1.0",
"xterm": "^5.3.0",
"xterm-addon-fit": "^0.8.0",
"xterm-addon-search": "^0.13.0"
"xterm-addon-search": "^0.13.0",
"esbuild": "^0.20.0",
"standard": "^17.1.0"
},
"scripts": {
"build": "ssc build -r -o",
Expand All @@ -27,6 +24,9 @@
"author": "Socket Supply Co. <[email protected]>",
"license": "MIT",
"dependencies": {
"@socketsupply/indexed": "^1.0.3",
"@socketsupply/tonic": "^15.1.2",
"@socketsupply/components": "^14.1.0",
"@socketsupply/socket": "^0.5.4"
}
}
2 changes: 1 addition & 1 deletion socket.ini
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ name = "union"
output = "build"

; The build script. It runs before the `[build] copy` phase.
; script = "node build.js"
script = "node build.js"

; Key value pairs added to the envrionment.
[env]
Expand Down
2 changes: 1 addition & 1 deletion src/components/confirm.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TonicDialog } from 'npm:@socketsupply/components/dialog'
import { TonicDialog } from '@socketsupply/components/dialog'

class DialogConfirm extends TonicDialog {
async prompt (opts) {
Expand Down
4 changes: 2 additions & 2 deletions src/components/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import fs from 'socket:fs'
import path from 'socket:path'
import { sha256 } from 'socket:network'

import * as monaco from 'npm:monaco-editor'
import Tonic from 'npm:@socketsupply/tonic'
import Tonic from '@socketsupply/tonic'
import { monaco } from '../vendor.js'

function rgbaToHex (rgbaString) {
const rgbaValues = rgbaString.match(/\d+/g)
Expand Down
3 changes: 2 additions & 1 deletion src/components/git-status.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Tonic from 'npm:@socketsupply/tonic'
import { exec } from 'socket:child_process'

import Tonic from '@socketsupply/tonic'

class GitStatus extends Tonic {
async * render () {
yield this.html`
Expand Down
3 changes: 2 additions & 1 deletion src/components/patch-requests.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import Tonic from 'npm:@socketsupply/tonic'
import path from 'socket:path'
import fs from 'socket:fs'
import { exec } from 'socket:child_process'

import Tonic from '@socketsupply/tonic'

class PatchRequests extends Tonic {
async click (e) {
const el = Tonic.match(e.target, '[data-event]')
Expand Down
2 changes: 1 addition & 1 deletion src/components/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import path from 'socket:path'
import { lookup } from 'socket:mime'
import { cp, rm } from '../lib/fs.js'

import Tonic from 'npm:@socketsupply/tonic'
import Tonic from '@socketsupply/tonic'

const EXPANDED_STATE = 1
const CLOSED_STATE = 0
Expand Down
3 changes: 2 additions & 1 deletion src/components/properties.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Tonic from 'npm:@socketsupply/tonic'
import process from 'socket:process'

import Tonic from '@socketsupply/tonic'

import Config from '../lib/config.js'

class AppProperties extends Tonic {
Expand Down
4 changes: 2 additions & 2 deletions src/components/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import fs from 'socket:fs'
import path from 'socket:path'
import { exec, execSync } from 'socket:child_process'

import Tonic from 'npm:@socketsupply/tonic'
import { TonicDialog } from 'npm:@socketsupply/components/dialog'
import Tonic from '@socketsupply/tonic'
import { TonicDialog } from '@socketsupply/components/dialog'

export class DialogPublish extends TonicDialog {
click (e) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/relative-date.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Tonic from 'npm:@socketsupply/tonic'
import Tonic from '@socketsupply/tonic'

const T_YEARS = 1000 * 60 * 60 * 24 * 365
const T_MONTHS = 1000 * 60 * 60 * 24 * 30
Expand Down
2 changes: 1 addition & 1 deletion src/components/sprite.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Tonic from 'npm:@socketsupply/tonic'
import Tonic from '@socketsupply/tonic'

class AppSprite extends Tonic {
render () {
Expand Down
4 changes: 2 additions & 2 deletions src/components/subscribe.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import fs from 'socket:fs'
import path from 'socket:path'
import { Encryption, sha256 } from 'socket:network'

import Tonic from 'npm:@socketsupply/tonic'
import { TonicDialog } from 'npm:@socketsupply/components/dialog'
import Tonic from '@socketsupply/tonic'
import { TonicDialog } from '@socketsupply/components/dialog'

export class DialogSubscribe extends TonicDialog {
async show () {
Expand Down
8 changes: 4 additions & 4 deletions src/components/terminal.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Tonic from 'npm:@socketsupply/tonic'
import { Terminal } from 'npm:xterm'
import { FitAddon as Resizer } from 'npm:xterm-addon-fit'
import { SearchAddon as Search } from 'npm:xterm-addon-search'
import Tonic from '@socketsupply/tonic'
import { Terminal } from '../vendor.js'
import { Resizer } from '../vendor.js'
import { Search } from '../vendor.js'

// const SECOND = 1000
// const MAX_ROWS = 30 * SECOND
Expand Down
Loading

0 comments on commit 25cc159

Please sign in to comment.