ããã«ã¡ããããã³ãã¨ã³ãã¨ãã¹ãã¼ããã¼ã ã®@nus3_ã§ãã
æè¿ã社å ç¨ã® npm ããã±ã¼ã¸ãä½ãå¿ è¦ãããããã®ããã±ã¼ã¸ã¯ä¾åãå°ãªããå®è£ ãã·ã³ãã«ã ã£ãã®ã§ãnpm ããã±ã¼ã¸ã®ä½æã«ã¯ Deno 㨠dnt ãæ¡ç¨ãã¾ããã
dnt ã¨ã¯
dnt 㯠Deno ã§å®è£ ããã¢ã¸ã¥ã¼ã«ã CJSãESM ã«å¯¾å¿ãã npm ããã±ã¼ã¸ã«å¤æãã¦ããããã«ããã¼ã«ã§ãã
使ãæ¹ãç°¡åã§ã次ã®ããã« dnt ãæä¾ããbuild
é¢æ°ã«ã¨ã³ããªã¼ãã¤ã³ããåºåå
ãªã©ã®å¿
è¦ãªæ
å ±ã渡ãã ãã§ãã
import { build } from "https://deno.land/x/[email protected]/mod.ts"; await build({ entryPoints: ["./mod/index.ts"], // Denoã§å®è£ ããã¢ã¸ã¥ã¼ã«ã®ã¨ã³ããªã¼ãã¤ã³ã outDir: "./npm", // åºåå ã®ãã£ã¬ã¯ã㪠shims: {}, // Denoåå空éãªã©Denoç¬èªã®å®è£ ãNode.jsããã©ã¦ã¶ã§å®è¡ã§ããshimã«ç½®ãæããè¨å® package: { // package.jsonã®å 容 name: "package-name", version: Deno.args[0], // ... }, });
ãã¨ã¯å®ç¾©ããbuild
é¢æ°ã Deno å´ã§å®è¡ããã° npm ããã±ã¼ã¸ãåºåããã¾ããå®éã« dnt ã®build
é¢æ°ãå®è¡ããã¨ä»¥ä¸ã®ãããªãã°ãã¿ã¼ããã«ä¸ã«è¡¨ç¤ºããã¾ãã
⯠deno task build Task build deno run -A build_npm.ts [dnt] Transforming... [dnt] Running npm install... added 4 packages, and audited 5 packages in 2s found 0 vulnerabilities [dnt] Building project... [dnt] Type checking ESM... [dnt] Emitting ESM package... [dnt] Emitting script package... [dnt] Running post build action... [dnt] Running tests... > test > node test_runner.js Running tests in ./script/nus3_test.js... test ãã¹ãã±ã¼ã¹ ... ok Running tests in ./esm/nus3_test.js... test ãã¹ãã±ã¼ã¹ ... ok [dnt] Complete!
ãã®ãã°ã«ã表示ããã¦ãã¾ãããdnt ã«ã¯å¤§ãã 2 ã¤ã®ç¹å¾´ãããã¾ãã
- Deno ã§å®è£
ããã¢ã¸ã¥ã¼ã«ã
npm:
specifiersããesm.shãªã©ã® CDNãImport Mapsãã npm ããã±ã¼ã¸ã使ç¨ãã¦ããå ´åããããã®ããã±ã¼ã¸ãä¾åé¢ä¿ã¨ã㦠npm ããã±ã¼ã¸ã® package.json ã«è¿½å ãã - ãã«ãå¾ã® ESMãCJS å½¢å¼ã®ãã¡ã¤ã«ããããã«å¯¾ã㦠Deno ã§å®è£ ãããã¹ãã Node.js ã§å®è¡ãã
dnt ã¯ã©ã®ããã« Deno ã®ã¢ã¸ã¥ã¼ã«ã npm ããã±ã¼ã¸ã¨ãã¦ãã«ãããã®ã
ã§ã¯ãå®éã« dnt ãã©ã®ããã« Deno ã®ã¢ã¸ã¥ã¼ã«ã npm ããã±ã¼ã¸ã«å¤æãã¦ããã®ãããã£ããã¨ããæµããè¦ã¦ã¿ã¾ãããã
dnt(v0.38.1 æç¹) ã®ãã£ã¬ã¯ããªæ§æã¯æ¬¡ã®ããã«ãªã£ã¦ãã¾ãã
. âââ Cargo.lock âââ Cargo.toml âââ LICENSE âââ README.md âââ deno.jsonc âââ lib // wasmã®åºåå ãshimsãts_morphã®importå âââ mod.ts // dntã®buildã¡ã½ãããå®ç¾©ããã¦ãå ´æ âââ rs-lib // deno_node_transform âââ rust-toolchain.toml âââ tests âââ transform.ts âââ wasm // dnt-wasm
ãã£ã¬ã¯ããªæ§æããããããéããdnt 㯠Deno ã®ã¢ã¸ã¥ã¼ã«ã¨ Rust ã®ã¯ã¬ã¼ããåä¸ãªãã¸ããªã§ç®¡çããã¦ãã¾ãã
dnt ã®build
é¢æ°ã¯ãªãã¸ããªã®ã«ã¼ãç´ä¸ã® mod.ts ã§å®ç¾©ããã¦ãããå¼æ°ã§æå®ãããã¨ã³ããªã¼ãã¤ã³ããªã©ã®æ
å ±ãtransform
é¢æ°ã«æ¸¡ãã¾ãã
ãã®transform
é¢æ°ã¯ dnt_wasm_bg.wasm ã¨ãã wasm ãã¡ã¤ã«ããæä¾ããã¦ãã¾ããdnt_wasm_bg.wasm 㯠wasmbuild ã使ã£ã¦ Rust ã®ã³ã¼ã(dnt-wasm)ãã³ã³ãã¤ã«ããããã®ã§ãã
dnt-wasm ã§ã¯ãdeno_node_transform ãæä¾ãã transform é¢æ°ãå®è¡ããã¦ãã¾ãã
çè
ã Rust ã®ç¥èãæµ
ããã¨ããã deno_node_transform ã®transform
é¢æ°ãè¡ãªã£ã¦ããå¦çã®è©³ç´°ãææ¡ã¯ã§ãã¦ããªããã§ãããtransform
é¢æ°ã®ã³ã¡ã³ããèªãéããã¨ã³ããªã¼ãã¤ã³ãã解æãã¦ãä¾åããã¢ã¸ã¥ã¼ã«ãåå¾ããTypeScript ã®ã³ã¼ããã¡ã¢ãªä¸ã«åºåãã¦ãããã§ãã
ãã®transform
ã®è¿ãå¤(TypeScript ã®ã³ã¼ã)ã ts_morphã¨ãã TypeScript Compiler API ã®ã©ããã¼ã«æ¸¡ãã¾ããts_morph ã使ã£ã¦ãTypeScript ã®ã³ã¼ãããåå®ç¾©ãã¡ã¤ã«ã¨ JS ã emitãã¦ãã¾ãã
ã¾ããemit ããéã«ãESMãCJSç¨ã®å¤æããã¦ãã¾ãã
Deno 㨠dnt ãæ¡ç¨ããçç±
å®éã«ããã³ãã¨ã³ãã¨ãã¹ãã¼ããã¼ã ã®æ¢æ±æéã« dnt ã試ããéã«ã次ã®ç¹ãè¯ãã¨æãã¦ãã¾ããã
- LintãFormatãTestãTypeCheck ãè¨å®ãªãã§ä½¿ãã
- CJSãESM 両æ¹ã«å¯¾å¿ãã npm ããã±ã¼ã¸ãä½æã§ãã
ã¾ããä»åä½æãã社å npm ããã±ã¼ã¸ã¯ä¾åãå°ãªããå®è£ ãã·ã³ãã«ã ã£ãã®ã§ãä»å¾ãä½ãåé¡ããã£ãéã«ç§»è¡ããã³ã¹ããä½ãã¨èããæ¡ç¨ã決ãã¾ããã
å®éã«æ¡ç¨ãã¦ã¿ã¦
æ¡ç¨ããçç±ã§ãè¿°ã¹ã¾ãããããã¯ã 1 çªè¯ãã£ãã®ã¯ãLinter ã Formatterãtsconfig ã®è¨å®ãããã«ããã«éçºãå§ããããç¹ã§ããããããã§å®è£ ãããæ©è½ã«éä¸ã§ããã¨æãã¦ãã¾ãã
ãã¹ãã«é¢ãã¦ããããã¥ã¡ã³ããèªãã¨ãã«ãã¤ã³ã§å ¥ã£ã¦ãããã¹ãç¨ã® API ã®ä½¿ãæ¹ãªã©ãããã«ç解ã§ããã¹ã ã¼ãºã«æ¸ããã¨ãã§ãã¾ãããï¼dnt ã§ãã¹ããå®è¡ãã㨠CJSãESM å½¢å¼ã®ãã¡ã¤ã«ããããã«å¯¾ãã¦ãã¹ããå®è¡ããã®ã§ãã¢ãã¯ãã¡ãã㨠restore ããªãã¨ãESM å½¢å¼ã ããã¹ãã¦ãCJS ã ãè½ã¡ããããªã±ã¼ã¹ã¯ããã¾ãããï¼
ä»åã¯ä½æããããã±ã¼ã¸ã®ä¾åé¢ä¿ãå°ãªããã¨ããããããã±ã¼ã¸ã®ã¢ãããã¼ãã¯æåã§è¡ãªã£ã¦ãã¾ãããéç¨ãç¶ãã¦ãããã¨ãèããã¨ã©ã®ããã«èªååãããã¯ä»å¾ã対å¿ããå¿ è¦ãããããã§ãã
ããããéç¨ãç¶ãã¦ããä¸ã§åé¡ãçºçãããã¨ãããããããã¾ããããä»åå®éã«æ¡ç¨ãã¦ã¿ã¦ãå°è¦æ¨¡ãª npm ããã±ã¼ã¸ãä½ãéã« Deno 㨠dnt ã使ãã¨èæ ®ãã¹ãç¹ãæ¸ãããå®è£ ãããæ©è½ã«ããã«çæã§ããã¨ã¦ãè¯ãã£ãã§ãã