@@ -3,6 +3,7 @@ const exorcist = require("exorcist");
33const rollup = require ( "rollup" ) ;
44const dts = require ( "rollup-plugin-dts" ) . default ;
55const commonjs = require ( "@rollup/plugin-commonjs" ) ;
6+ const { Extractor, ExtractorConfig } = require ( "@microsoft/api-extractor" ) ;
67const fs = require ( "node:fs" ) ;
78const path = require ( "node:path" ) ;
89const { minify } = require ( "terser" ) ;
@@ -123,23 +124,62 @@ async function buildRollup() {
123124 } ) ;
124125}
125126
126- function fixDtsOutputFlexible ( filePath ) {
127+ function runApiExtractor ( ) {
128+ const extractorConfigPath = path . resolve ( baseDir , "api-extractor.json" ) ;
129+ const extractorConfig = ExtractorConfig . loadFileAndPrepare ( extractorConfigPath ) ;
130+
131+ const { succeeded, errors, warnings } = Extractor . invoke ( extractorConfig , {
132+ localBuild : true ,
133+ showVerboseMessages : true ,
134+ } ) ;
135+
136+ if ( succeeded ) {
137+ console . log ( "✨ API Extractor completed successfully!" ) ;
138+ } else {
139+ throw new Error ( "💥API Extractor failed." ) ;
140+ }
141+ }
142+
143+ function fixDtsOutputFlexible ( filePath , log = false ) {
127144 let code = fs . readFileSync ( filePath , "utf8" ) ;
128145
129- const reg = new RegExp ( `export\s{\s${ script_name } \sas\sdefault\s};` ) ;
130- code = code . replace ( reg , `export default ${ script_name } ;` ) ;
146+ const regList = [
147+ // 修正をここに追加
148+ [
149+ `declare\\s+namespace\\s+(__(?:[a-z]+_)+[A-Za-z]+_js)\\s+{\\s+export\\s+{[\\s\\S]*?\\s+};\\s+}\\s+` ,
150+ ( a , b ) => {
151+ if ( log ) console . log ( `┃┃ namespace ${ b } : ${ CL . cyan ( "削除" ) } ` ) ;
152+ return "" ;
153+ } ,
154+ ] ,
155+ [
156+ `(\\s+)(__(?:[a-z]+_)+([A-Za-z]+)_js)` ,
157+ ( a , b , c , d ) => {
158+ if ( log ) console . log ( `┃┃ ${ c } -> ${ d } : ${ CL . cyan ( "統合" ) } ` ) ;
159+ return `${ b } ${ d } ` ;
160+ } ,
161+ ] ,
162+ ] ;
163+
164+ for ( const [ reg , rep ] of regList ) {
165+ const re = new RegExp ( reg , "gm" ) ;
166+ code = code . replace ( re , rep ) ;
167+ }
131168
132169 fs . writeFileSync ( filePath , code ) ;
133170}
134171
135172( async ( ) => {
136173 const debug = true ;
174+ // 動作確認用 ログ表示
175+ const logView = true ;
176+ //
137177 const start = performance . now ( ) ;
138178 try {
139179 console . log ( `🎉 ${ CL . brightYellow ( "ビルド開始" ) } ` ) ;
140180 //
141181 console . log ( `┣🔁 ${ CL . brightWhite ( "index.js自動生成開始..." ) } ` ) ;
142- generateIndex ( entryDir ) ;
182+ generateIndex ( entryDir , logView ) ;
143183 console . log ( `┃┗🌱 ${ CL . brightWhite ( "自動生成完了" ) } ` ) ;
144184 //
145185 console . log ( `┃🗑️ ${ CL . brightWhite ( "distフォルダリセット" ) } ` ) ;
@@ -166,13 +206,14 @@ function fixDtsOutputFlexible(filePath) {
166206 console . log ( `┃⛳ ${ CL . brightWhite ( "rollup用entrypoint作成" ) } ` ) ;
167207 createEntryEndpoint ( entryTypesPath ) ;
168208 console . log ( "┃📦 .d.ts を rollup中..." ) ;
169- await buildRollup ( ) ;
209+ //await buildRollup();
210+ runApiExtractor ( ) ;
170211 console . log ( `┃┗✅ ${ CL . brightWhite ( "rollup完了" ) } : ${ getRelativePath ( typesPath ) } ` ) ;
171212 console . log ( `┃🗑️ ${ CL . brightWhite ( "types仮フォルダcleanup" ) } ` ) ;
172- prepareDir ( typesTmpDir ) ;
173- console . log ( `┃🌵 ${ CL . brightWhite ( "export問題を解決 " ) } ` ) ;
174- fixDtsOutputFlexible ( typesPath ) ;
175- console . log ( `┃┗✅ ${ CL . brightWhite ( "export default 生成完了 " ) } : ${ getRelativePath ( typesPath ) } ` ) ;
213+ // prepareDir(typesTmpDir);
214+ console . log ( `┃🌵 ${ CL . brightWhite ( "予測候補問題を解決 " ) } ` ) ;
215+ fixDtsOutputFlexible ( typesPath , logView ) ;
216+ console . log ( `┃┗✅ ${ CL . brightWhite ( "予測候補問題 修正完了 " ) } : ${ getRelativePath ( typesPath ) } ` ) ;
176217 showFileSize ( typesPath ) ;
177218 }
178219
0 commit comments