-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into ISSUE-203
- Loading branch information
Showing
21 changed files
with
1,286 additions
and
1,725 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
const { config } = require('@swc/core/spack') | ||
|
||
const { config } = require("@swc/core/spack"); | ||
|
||
module.exports = config({ | ||
entry: { | ||
'web': __dirname + '/src/index.ts', | ||
}, | ||
output: { | ||
path: __dirname + '/lib' | ||
}, | ||
module: {}, | ||
}); | ||
entry: { | ||
web: __dirname + "/src/index.ts", | ||
}, | ||
output: { | ||
path: __dirname + "/lib", | ||
}, | ||
module: {}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export const A = 'foo'; | ||
export const B = 'bar'; | ||
export const A = "foo"; | ||
export const B = "bar"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import { B } from "./common"; | ||
|
||
console.log(B) | ||
console.log(B); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
const { config } = require('@swc/core/spack') | ||
|
||
const { config } = require("@swc/core/spack"); | ||
|
||
module.exports = config({ | ||
entry: { | ||
'web': __dirname + '/src/web.ts', | ||
'android': __dirname + '/src/android.ts', | ||
}, | ||
output: { | ||
path: __dirname + '/lib' | ||
}, | ||
module: {}, | ||
}); | ||
entry: { | ||
web: __dirname + "/src/web.ts", | ||
android: __dirname + "/src/android.ts", | ||
}, | ||
output: { | ||
path: __dirname + "/lib", | ||
}, | ||
module: {}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
import './common'; | ||
import "./common"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
console.log('initializing') | ||
console.log("initializing"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
import './common'; | ||
import "./common"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
const { config } = require('@swc/core/spack') | ||
|
||
const { config } = require("@swc/core/spack"); | ||
|
||
module.exports = config({ | ||
entry: { | ||
'web': __dirname + '/src/index.ts', | ||
}, | ||
output: { | ||
path: __dirname + '/lib' | ||
}, | ||
module: {}, | ||
}); | ||
entry: { | ||
web: __dirname + "/src/index.ts", | ||
}, | ||
output: { | ||
path: __dirname + "/lib", | ||
}, | ||
module: {}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import { join } from 'path'; | ||
import { join } from "path"; | ||
|
||
export const A = join(__dirname, 'src'); | ||
export const A = join(__dirname, "src"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import { A } from "./common"; | ||
|
||
console.log(A) | ||
console.log(A); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,74 @@ | ||
import { bundle } from '@swc/core'; | ||
import { mkdir, writeFile } from 'fs'; | ||
import { basename, dirname, extname, join, relative } from 'path' | ||
import { promisify } from 'util'; | ||
import { bundle } from "@swc/core"; | ||
import { mkdir, writeFile } from "fs"; | ||
import { basename, dirname, extname, join, relative } from "path"; | ||
import { promisify } from "util"; | ||
|
||
import parseSpackArgs from './options'; | ||
import parseSpackArgs from "./options"; | ||
|
||
const write = promisify(writeFile); | ||
const makeDir = promisify(mkdir); | ||
|
||
|
||
(async () => { | ||
const { spackOptions } = await parseSpackArgs(process.argv); | ||
const { spackOptions } = await parseSpackArgs(process.argv); | ||
|
||
function isUserDefinedEntry(name: string) { | ||
if (typeof spackOptions.entry === 'string') { | ||
return spackOptions.entry === name | ||
} | ||
if (Array.isArray(spackOptions.entry)) { | ||
for (const e of spackOptions.entry) { | ||
if (e === name) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
function isUserDefinedEntry(name: string) { | ||
if (typeof spackOptions.entry === "string") { | ||
return spackOptions.entry === name; | ||
} | ||
if (Array.isArray(spackOptions.entry)) { | ||
for (const e of spackOptions.entry) { | ||
if (e === name) { | ||
return true; | ||
} | ||
|
||
return name in spackOptions.entry; | ||
} | ||
return false; | ||
} | ||
|
||
return name in spackOptions.entry; | ||
} | ||
|
||
async function build() { | ||
const bundleStart = process.hrtime(); | ||
const output = await bundle(spackOptions); | ||
const bundleEnd = process.hrtime(bundleStart); | ||
console.info(`Bundling done: ${bundleEnd[0]}s ${bundleEnd[1] / 1000000}ms`); | ||
|
||
const emitStart = process.hrtime(); | ||
if (spackOptions.output?.path) { | ||
await Object.keys(output).map(async (name) => { | ||
let fullPath = ''; | ||
if (isUserDefinedEntry(name)) { | ||
fullPath = join(spackOptions.output.path, spackOptions.output.name.replace('[name]', name)); | ||
} else { | ||
const ext = extname(name); | ||
const base = basename(name, ext); | ||
const filename = relative(process.cwd(), name); | ||
fullPath = join(spackOptions.output.path, dirname(filename), `${base}.js`) | ||
} | ||
async function build() { | ||
const bundleStart = process.hrtime(); | ||
const output = await bundle(spackOptions); | ||
const bundleEnd = process.hrtime(bundleStart); | ||
console.info(`Bundling done: ${bundleEnd[0]}s ${bundleEnd[1] / 1000000}ms`); | ||
|
||
await makeDir(dirname(fullPath), { recursive: true }); | ||
await write(fullPath, output[name].code, 'utf-8'); | ||
if (output[name].map) { | ||
await write(`${fullPath}.map`, output[name].map, 'utf-8') | ||
} | ||
}); | ||
const emitStart = process.hrtime(); | ||
if (spackOptions.output?.path) { | ||
await Object.keys(output).map(async name => { | ||
let fullPath = ""; | ||
if (isUserDefinedEntry(name)) { | ||
fullPath = join( | ||
spackOptions.output.path, | ||
spackOptions.output.name.replace("[name]", name) | ||
); | ||
} else { | ||
throw new Error('Cannot print to stdout: not implemented yet') | ||
const ext = extname(name); | ||
const base = basename(name, ext); | ||
const filename = relative(process.cwd(), name); | ||
fullPath = join( | ||
spackOptions.output.path, | ||
dirname(filename), | ||
`${base}.js` | ||
); | ||
} | ||
const emitEnd = process.hrtime(emitStart); | ||
console.info(`Done: ${emitEnd[0]}s ${emitEnd[1] / 1000000}ms`); | ||
|
||
await makeDir(dirname(fullPath), { recursive: true }); | ||
await write(fullPath, output[name].code, "utf-8"); | ||
if (output[name].map) { | ||
await write(`${fullPath}.map`, output[name].map, "utf-8"); | ||
} | ||
}); | ||
} else { | ||
throw new Error("Cannot print to stdout: not implemented yet"); | ||
} | ||
const emitEnd = process.hrtime(emitStart); | ||
console.info(`Done: ${emitEnd[0]}s ${emitEnd[1] / 1000000}ms`); | ||
} | ||
|
||
// if (cliOptions.watch) { | ||
// throw new Error('watch is not implemented yet') | ||
// } | ||
// if (cliOptions.watch) { | ||
// throw new Error('watch is not implemented yet') | ||
// } | ||
|
||
await build(); | ||
})() | ||
await build(); | ||
})(); |
Oops, something went wrong.