|
1 | 1 | #!/usr/bin/env node |
2 | 2 |
|
3 | | -import { componentize } from "@bytecodealliance/componentize-js"; |
| 3 | +import { componentize } from '@bytecodealliance/componentize-js'; |
4 | 4 | //@ts-ignore https://github.com/bytecodealliance/ComponentizeJS/pull/198 |
5 | | -import { version } from "@bytecodealliance/componentize-js" |
6 | | -import { getPackagesWithWasiDeps, processWasiDeps } from "./wasiDepsParser.js"; |
| 5 | +import { version } from '@bytecodealliance/componentize-js'; |
| 6 | +import { getPackagesWithWasiDeps, processWasiDeps } from './wasiDepsParser.js'; |
7 | 7 | import { basename } from 'node:path'; |
8 | 8 |
|
9 | | -import { calculateChecksum, getPackageVersion, saveBuildData } from "./utils.js"; |
10 | | -import { getCliArgs } from "./cli.js"; |
11 | | -import { getBuildDataPath, ShouldComponentize } from "./build.js"; |
12 | | -import { readFile, writeFile } from "node:fs/promises"; |
13 | | -import { mergeWit } from "../lib/wit_tools.js" |
| 9 | +import { |
| 10 | + calculateChecksum, |
| 11 | + getPackageVersion, |
| 12 | + saveBuildData, |
| 13 | +} from './utils.js'; |
| 14 | +import { getCliArgs } from './cli.js'; |
| 15 | +import { getBuildDataPath, ShouldComponentize } from './build.js'; |
| 16 | +import { readFile, writeFile } from 'node:fs/promises'; |
| 17 | +import { mergeWit } from '../lib/wit_tools.js'; |
14 | 18 |
|
15 | 19 | async function main() { |
16 | 20 | try { |
17 | 21 | // Parse CLI args |
18 | | - let CliArgs = getCliArgs() |
| 22 | + let CliArgs = getCliArgs(); |
19 | 23 | let src = CliArgs.input; |
20 | 24 | let outputPath = CliArgs.output; |
21 | 25 |
|
22 | 26 | // Can remove the explicit typing once https://github.com/bytecodealliance/ComponentizeJS/pull/198 is merged and released |
23 | 27 | let componentizeVersion = version as string; |
24 | 28 |
|
25 | 29 | // Small optimization to skip componentization if the source file hasn't changed |
26 | | - if (!await ShouldComponentize(src, outputPath, componentizeVersion)) { |
27 | | - console.log("No changes detected in source file. Skipping componentization."); |
| 30 | + if (!(await ShouldComponentize(src, outputPath, componentizeVersion))) { |
| 31 | + console.log( |
| 32 | + 'No changes detected in source file. Skipping componentization.', |
| 33 | + ); |
28 | 34 | return; |
29 | 35 | } |
30 | | - console.log("Componentizing..."); |
| 36 | + console.log('Componentizing...'); |
31 | 37 |
|
32 | 38 | // generate wit world string |
33 | 39 | let wasiDeps = getPackagesWithWasiDeps(process.cwd(), new Set(), true); |
34 | 40 |
|
35 | 41 | let { witPaths, targetWorlds } = processWasiDeps(wasiDeps); |
36 | 42 |
|
37 | 43 | // Get inline wit by merging the wits specified by all the dependencies |
38 | | - let inlineWit = mergeWit(witPaths, targetWorlds, "combined", "combined-wit:[email protected]"); |
| 44 | + let inlineWit = mergeWit( |
| 45 | + witPaths, |
| 46 | + targetWorlds, |
| 47 | + 'combined', |
| 48 | + |
| 49 | + ); |
39 | 50 |
|
40 | 51 | const source = await readFile(src, 'utf8'); |
41 | 52 |
|
42 | 53 | const { component } = await componentize(source, inlineWit, { |
43 | 54 | sourceName: basename(src), |
44 | 55 | // TODO: CHeck if we need to enable http |
45 | 56 | //@ts-ignore |
46 | | - enableFeatures: ["http"], |
| 57 | + enableFeatures: ['http'], |
47 | 58 | }); |
48 | 59 |
|
49 | 60 | await writeFile(outputPath, component); |
50 | 61 |
|
51 | 62 | // Save the checksum of the input file along with the componentize version |
52 | | - await saveBuildData(getBuildDataPath(src), await calculateChecksum(src), componentizeVersion); |
| 63 | + await saveBuildData( |
| 64 | + getBuildDataPath(src), |
| 65 | + await calculateChecksum(src), |
| 66 | + componentizeVersion, |
| 67 | + ); |
53 | 68 |
|
54 | | - console.log("Component successfully written."); |
| 69 | + console.log('Component successfully written.'); |
| 70 | + } catch (error) { |
| 71 | + console.error( |
| 72 | + 'An error occurred during the componentization process:', |
| 73 | + error, |
| 74 | + ); |
| 75 | + console.error('Error:', error); |
55 | 76 | } |
56 | | - catch (error) { |
57 | | - console.error("An error occurred during the componentization process:", error); |
58 | | - console.error("Error:", error); |
59 | | - } |
60 | | - |
61 | 77 | } |
62 | 78 |
|
63 | 79 | main(); |
0 commit comments