1- import * as fs from "std/fs/mod.ts " ;
2- import * as path from "std/path/mod.ts " ;
1+ import * as fs from "@ std/fs" ;
2+ import * as path from "@ std/path" ;
33import type * as types from "./types.ts" ;
44import { expandSourcePlaceholders } from "./utils/source_code.ts" ;
55import { formatMarkdown } from "./utils/format_markdown.ts" ;
66import { formatDefinitionDescriptions } from "./utils/format_definition_descriptions.ts" ;
77import { fileChecksum } from "./utils/checksum.ts" ;
8- import checksums from "./checksums.json" assert { type : "json" } ;
8+ import { compileTypeScript } from "./tsc.ts" ;
9+ import checksums from "./checksums.json" with { type : "json" } ;
910import { VERSION } from "./version.ts" ;
10- import packageJson from "../dist/node/package.json" assert { type : "json" } ;
11+ import packageJson from "../dist/node/package.json" with { type : "json" } ;
1112
1213// -----------------------------------------------------------------------------
1314
@@ -50,7 +51,6 @@ drafts.sort((a, b) => a.localeCompare(b));
5051// Process each draft
5152
5253for ( const draftId of drafts ) {
53- const nodeDraftId = draftId . replaceAll ( "_" , "-" ) ;
5454 const draftDir = path . join ( SRC_DIR , "draft" , draftId ) ;
5555 const draftDefFilename = path . join ( draftDir , "definition.ts" ) ;
5656 const draftDefChecksum = await fileChecksum ( draftDefFilename ) ;
@@ -105,7 +105,7 @@ for (const draftId of drafts) {
105105 draftSpec as unknown as types . ValidationSpecDefinition ,
106106 ) ;
107107
108- const outputFilename = path . join ( NODE_DIR , `draft- ${ nodeDraftId } .ts` ) ;
108+ const outputFilename = path . join ( DENO_DIR , `draft_ ${ draftId } .ts` ) ;
109109 await Deno . writeTextFile (
110110 outputFilename ,
111111 [
@@ -115,43 +115,17 @@ for (const draftId of drafts) {
115115 modCode ,
116116 ] . join ( "\n" ) ,
117117 ) ;
118- await Deno . run ( { cmd : [ "deno" , "fmt" , "--quiet" , outputFilename ] } ) . status ( ) ;
119-
120- // Copy to the deno directory
121- await fs . copy (
122- outputFilename ,
123- path . join ( DENO_DIR , `draft_${ draftId } .ts` ) ,
124- { overwrite : true } ,
125- ) ;
118+ const fmtCommand = new Deno . Command ( "deno" , {
119+ args : [ "fmt" , "--quiet" , outputFilename ] ,
120+ } ) ;
121+ await fmtCommand . output ( ) ;
126122
127123 // -------------------------------------------------------------------------
128124 // Compile to JS
129125 // -------------------------------------------------------------------------
130- const { files } = await Deno . emit ( outputFilename , {
131- bundle : "module" ,
132- compilerOptions : { target : "es6" } ,
133- } ) ;
134-
135- const js = files [ "deno:///bundle.js" ] ;
136- const map = files [ "deno:///bundle.js.map" ] ;
137-
138- // Write to the node directory
139- const mapJson = JSON . parse ( map ) as { sources : string [ ] } ;
140- mapJson . sources = mapJson . sources . map ( ( source ) => path . basename ( source ) ) ;
141-
142- await Deno . writeTextFile (
143- path . join ( NODE_DIR , `draft-${ nodeDraftId } .js` ) ,
144- [
145- `/// <reference types="./draft-${ nodeDraftId } .ts" />` ,
146- "// @generated" ,
147- js ,
148- `//# sourceMappingURL=draft-${ nodeDraftId } .js.map` ,
149- ] . join ( "\n" ) ,
150- ) ;
151-
152- await Deno . writeTextFile (
153- path . join ( NODE_DIR , `draft-${ nodeDraftId } .js.map` ) ,
154- JSON . stringify ( mapJson ) ,
126+ await compileTypeScript (
127+ outputFilename ,
128+ NODE_DIR ,
155129 ) ;
156130
157131 console . log ( `draft_${ draftId } : complete` ) ;
@@ -185,8 +159,6 @@ if (latestDraft === undefined) {
185159 throw new Error ( "TODO" ) ;
186160}
187161
188- const nodeLatestDraft = latestDraft . replaceAll ( "_" , "-" ) ;
189-
190162await Deno . writeTextFile (
191163 path . join ( DENO_DIR , "draft_latest.ts" ) ,
192164 `export * from "./draft_${ latestDraft } .ts";` ,
@@ -224,11 +196,10 @@ for (const readmeFilename of readmeFilenames) {
224196 } )
225197 . replaceAll ( "{LATEST_DRAFT}" , latestDraft ) ,
226198 ) ;
227- const p = Deno . run ( {
228- cmd : [ "deno" , "fmt" , "--quiet" , readmeFilename . output ] ,
199+ const fmtCommand = new Deno . Command ( "deno" , {
200+ args : [ "fmt" , "--quiet" , readmeFilename . output ] ,
229201 } ) ;
230- await p . status ( ) ;
231- p . close ( ) ;
202+ await fmtCommand . output ( ) ;
232203}
233204
234205// -----------------------------------------------------------------------------
@@ -276,16 +247,26 @@ for (const dir of ALL_DIST_DIRS) {
276247// -----------------------------------------------------------------------------
277248{
278249 packageJson . version = VERSION ;
279- packageJson . main = `./draft-${ nodeLatestDraft } .js` ;
250+ packageJson . main = `./draft_${ latestDraft } .js` ;
251+ packageJson . types = `./draft_${ latestDraft } .d.ts` ;
280252 // @ts -expect-error this is valid
281253 packageJson . exports = {
282- "." : `./draft-${ nodeLatestDraft } .js` ,
254+ "." : {
255+ types : `./draft_${ latestDraft } .d.ts` ,
256+ default : `./draft_${ latestDraft } .js` ,
257+ } ,
283258 ...Object . fromEntries (
284259 drafts . map ( (
285260 draftId ,
286261 ) => {
287262 const nodeDraftId = draftId . replaceAll ( "_" , "-" ) ;
288- return [ `./draft-${ nodeDraftId } ` , `./draft-${ nodeDraftId } .js` ] ;
263+ return [
264+ `./draft-${ nodeDraftId } ` ,
265+ {
266+ types : `./draft_${ draftId } .d.ts` ,
267+ default : `./draft_${ draftId } .js` ,
268+ } ,
269+ ] ;
289270 } ) ,
290271 ) ,
291272 } ;
0 commit comments