nadesiko3 3.3.45 → 3.3.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +143 -132
- package/batch/browsers.template.md +3 -3
- package/batch/build_browsers.nako3 +72 -72
- package/batch/build_command.nako3 +44 -44
- package/batch/build_nako_version.nako3 +42 -42
- package/batch/calc_hash.nako3 +29 -29
- package/batch/cmd_txt2json.nako3 +74 -74
- package/batch/command.txt +270 -338
- package/batch/command_nakopad.txt +9 -69
- package/batch/download-extlib.nako3 +43 -43
- package/batch/gen_command_nakopad.nako3 +57 -57
- package/batch/jsplugin2text.nako3 +285 -285
- package/batch/pickup_command.nako3 +110 -110
- package/batch/pickup_reserved_words.nako3 +11 -11
- package/batch/publish_version.nako3 +46 -46
- package/batch/show_agents.js +14 -14
- package/batch/turtle2js.nako3 +21 -21
- package/bin/cnako3 +10 -10
- package/core/.editorconfig +6 -0
- package/core/.eslintrc.cjs +33 -0
- package/core/.github/dependabot.yml +7 -0
- package/core/.github/workflows/nodejs.yml +37 -0
- package/core/.github/workflows/super-linter.yml +61 -0
- package/core/.github/workflows/textlint.yml +199 -0
- package/core/LICENSE +21 -0
- package/core/README.md +66 -0
- package/core/batch/build_nako_version.nako3 +42 -0
- package/core/command/snako.mjs +105 -0
- package/core/command/snako.mts +116 -0
- package/core/index.mjs +21 -0
- package/core/index.mts +21 -0
- package/core/package.json +47 -0
- package/core/sample/hello.nako3 +7 -0
- package/core/sample/hoge.mjs +4 -0
- package/core/sample/hoge.mts +6 -0
- package/core/src/nako3.mjs +858 -0
- package/core/src/nako3.mts +967 -0
- package/core/src/nako_colors.mjs +78 -0
- package/core/src/nako_colors.mts +86 -0
- package/core/src/nako_core_version.mjs +8 -0
- package/core/src/nako_core_version.mts +19 -0
- package/core/src/nako_csv.mjs +185 -0
- package/core/src/nako_csv.mts +188 -0
- package/core/src/nako_errors.mjs +173 -0
- package/core/src/nako_errors.mts +197 -0
- package/core/src/nako_from_dncl.mjs +255 -0
- package/core/src/nako_from_dncl.mts +250 -0
- package/core/src/nako_gen.mjs +1648 -0
- package/core/src/nako_gen.mts +1719 -0
- package/core/src/nako_gen_async.mjs +1659 -0
- package/core/src/nako_gen_async.mts +1732 -0
- package/core/src/nako_global.mjs +107 -0
- package/core/src/nako_global.mts +138 -0
- package/core/src/nako_indent.mjs +445 -0
- package/core/src/nako_indent.mts +492 -0
- package/core/src/nako_josi_list.mjs +38 -0
- package/core/src/nako_josi_list.mts +45 -0
- package/core/src/nako_lex_rules.mjs +253 -0
- package/core/src/nako_lex_rules.mts +260 -0
- package/core/src/nako_lexer.mjs +609 -0
- package/core/src/nako_lexer.mts +612 -0
- package/core/src/nako_logger.mjs +199 -0
- package/core/src/nako_logger.mts +232 -0
- package/core/src/nako_parser3.mjs +2439 -0
- package/core/src/nako_parser3.mts +2195 -0
- package/core/src/nako_parser_base.mjs +370 -0
- package/core/src/nako_parser_base.mts +370 -0
- package/core/src/nako_parser_const.mjs +37 -0
- package/core/src/nako_parser_const.mts +37 -0
- package/core/src/nako_prepare.mjs +304 -0
- package/core/src/nako_prepare.mts +315 -0
- package/core/src/nako_reserved_words.mjs +38 -0
- package/core/src/nako_reserved_words.mts +38 -0
- package/core/src/nako_source_mapping.mjs +207 -0
- package/core/src/nako_source_mapping.mts +262 -0
- package/core/src/nako_test.mjs +37 -0
- package/core/src/nako_types.mjs +25 -0
- package/core/src/nako_types.mts +151 -0
- package/core/src/plugin_csv.mjs +49 -0
- package/core/src/plugin_csv.mts +50 -0
- package/core/src/plugin_math.mjs +328 -0
- package/core/src/plugin_math.mts +326 -0
- package/core/src/plugin_promise.mjs +91 -0
- package/core/src/plugin_promise.mts +91 -0
- package/core/src/plugin_system.mjs +2832 -0
- package/core/src/plugin_system.mts +2690 -0
- package/core/src/plugin_test.mjs +34 -0
- package/core/src/plugin_test.mts +34 -0
- package/core/test/array_test.mjs +34 -0
- package/core/test/basic_test.mjs +344 -0
- package/core/test/calc_test.mjs +140 -0
- package/core/test/core_module_test.mjs +23 -0
- package/core/test/debug_test.mjs +16 -0
- package/core/test/dncl_test.mjs +94 -0
- package/core/test/error_message_test.mjs +210 -0
- package/core/test/error_test.mjs +16 -0
- package/core/test/flow_test.mjs +373 -0
- package/core/test/func_call.mjs +160 -0
- package/core/test/func_test.mjs +149 -0
- package/core/test/indent_test.mjs +364 -0
- package/core/test/lex_test.mjs +168 -0
- package/core/test/literal_test.mjs +73 -0
- package/core/test/nako_lexer_test.mjs +35 -0
- package/core/test/nako_logger_test.mjs +76 -0
- package/core/test/nako_logger_test.mts +78 -0
- package/core/test/plugin_csv_test.mjs +38 -0
- package/core/test/plugin_promise_test.mjs +18 -0
- package/core/test/plugin_system_test.mjs +630 -0
- package/core/test/prepare_test.mjs +96 -0
- package/core/test/re_test.mjs +22 -0
- package/core/test/side_effects_test.mjs +92 -0
- package/core/test/variable_scope_test.mjs +149 -0
- package/core/tsconfig.json +101 -0
- package/demo/ace_editor.html +89 -89
- package/demo/ace_editor_tabs.html +161 -161
- package/demo/basic.html +71 -71
- package/demo/browsers.html +9 -10
- package/demo/css/basic.css +3 -3
- package/demo/css/common.css +157 -157
- package/demo/css/editor.css +8 -8
- package/demo/css/flow.css +3 -3
- package/demo/css/index.css +3 -3
- package/demo/flow.html +98 -98
- package/demo/graph.html +53 -53
- package/demo/image/nakopad-icon256.png +0 -0
- package/demo/index.html +133 -133
- package/demo/js/common.js +17 -17
- package/demo/js/turtle3d_test.js +44 -44
- package/demo/js/turtle_test.js +45 -45
- package/demo/nako3/calc.nako3 +4 -4
- package/demo/runscript.html +47 -47
- package/demo/runscript2.html +33 -33
- package/demo/runscript3.html +35 -35
- package/demo/runscript4.html +33 -33
- package/demo/turtle.html +58 -58
- package/demo/turtle2.html +141 -141
- package/demo/turtle3.html +279 -279
- package/demo/turtle3d.html +58 -58
- package/demo/turtle3d2.html +107 -107
- package/demo/version.html +24 -24
- package/doc/SETUP.md +157 -157
- package/doc/about.md +17 -17
- package/doc/browsers.md +26 -26
- package/doc/docgen.md +21 -21
- package/doc/editor.md +44 -44
- package/doc/files.md +39 -39
- package/doc/plugins.md +234 -234
- package/doc/release.md +79 -79
- package/doc/textlint.md +43 -43
- package/doc/win32.md +57 -57
- package/package.json +195 -192
- package/release/_hash.txt +28 -28
- package/release/_script-tags.txt +14 -14
- package/release/command.json +1 -1
- package/release/command.json.js +1 -1
- package/release/command_cnako3.json +1 -1
- package/release/command_list.json +1 -1
- package/release/editor.js +1 -1
- package/release/nako_gen_async.js +1 -1
- package/release/plugin_csv.js +1 -1
- package/release/stats.json +1 -1
- package/release/version.js +1 -1
- package/release/wnako3.js +1 -1
- package/release/wnako3webworker.js +1 -1
- package/src/browsers.txt +11 -12
- package/src/browsers_agents.json +2 -2
- package/src/browsers_agents.mjs +1 -1
- package/src/cnako3.mjs +17 -10
- package/src/cnako3.mts +18 -12
- package/src/cnako3mod.mjs +707 -687
- package/src/cnako3mod.mts +712 -696
- package/src/commander_ja.mjs +164 -164
- package/src/commander_ja.mts +161 -161
- package/src/enako3.mjs +68 -69
- package/src/era.mjs +22 -22
- package/src/image_turtle-elephant.mjs +2 -5
- package/src/image_turtle-panda.mjs +2 -5
- package/src/image_turtle64.mjs +2 -5
- package/src/index.mjs +9 -9
- package/src/index.mts +10 -11
- package/src/nako3editorfix.sfd +106 -106
- package/src/nako_version.mjs +8 -8
- package/src/nako_version.mts +2 -2
- package/src/plugin_browser.mjs +213 -212
- package/src/plugin_browser.mts +206 -205
- package/src/plugin_browser_ajax.mjs +399 -399
- package/src/plugin_browser_audio.mjs +109 -109
- package/src/plugin_browser_canvas.mjs +449 -449
- package/src/plugin_browser_chart.mjs +294 -294
- package/src/plugin_browser_color.mjs +49 -49
- package/src/plugin_browser_crypto.mjs +26 -26
- package/src/plugin_browser_dialog.mjs +53 -53
- package/src/plugin_browser_dom_basic.mjs +336 -336
- package/src/plugin_browser_dom_event.mjs +193 -193
- package/src/plugin_browser_dom_parts.mjs +396 -396
- package/src/plugin_browser_geolocation.mjs +51 -51
- package/src/plugin_browser_hotkey.mjs +25 -25
- package/src/plugin_browser_html.mjs +59 -59
- package/src/plugin_browser_in_worker.mjs +45 -45
- package/src/plugin_browser_location.mjs +21 -21
- package/src/plugin_browser_speech.mjs +111 -111
- package/src/plugin_browser_storage.mjs +121 -121
- package/src/plugin_browser_system.mjs +31 -31
- package/src/plugin_browser_websocket.mjs +73 -73
- package/src/plugin_caniuse.mjs +29 -29
- package/src/plugin_datetime.mjs +394 -394
- package/src/plugin_httpserver.mjs +277 -0
- package/src/plugin_httpserver.mts +286 -0
- package/src/plugin_kansuji.mjs +224 -224
- package/src/plugin_keigo.mjs +55 -55
- package/src/plugin_markup.mjs +32 -32
- package/src/plugin_node.mjs +1047 -1047
- package/src/plugin_node.mts +980 -980
- package/src/plugin_turtle.mjs +647 -647
- package/src/plugin_webworker.mjs +334 -334
- package/src/plugin_weykturtle3d.mjs +1214 -1214
- package/src/plugin_worker.mjs +95 -95
- package/src/repl.nako3 +63 -63
- package/src/wnako3.mjs +12 -12
- package/src/wnako3.mts +11 -11
- package/src/wnako3_editor.css +215 -215
- package/src/wnako3_editor.mjs +1542 -1542
- package/src/wnako3_editor.mts +1657 -1656
- package/src/wnako3mod.mjs +213 -213
- package/src/wnako3mod.mts +214 -214
- package/src/wnako3webworker.mjs +69 -68
- package/test/ace_editor/karma.config.js +94 -94
- package/test/ace_editor/test/.babelrc.json +3 -3
- package/test/ace_editor/test/ace_editor_test.js +178 -178
- package/test/ace_editor/test/html/custom_context.html +139 -139
- package/test/async/async_basic_test.mjs +122 -122
- package/test/browser/karma.config.js +221 -221
- package/test/browser/test/.babelrc.json +3 -3
- package/test/browser/test/compare_util.js +50 -50
- package/test/browser/test/html/div_basic.html +2 -2
- package/test/browser/test/html/event_dom_form.html +4 -4
- package/test/browser/test/html/event_dom_scrolldiv.html +5 -5
- package/test/browser/test/import_plugin_checker.js +24 -24
- package/test/browser/test/plugin_browser_test.js +51 -51
- package/test/browser/test/plugin_browser_test_ajax.js +123 -123
- package/test/browser/test/plugin_browser_test_color.js +18 -18
- package/test/browser/test/plugin_browser_test_dialog.js +72 -72
- package/test/browser/test/plugin_browser_test_dom_event.js +598 -598
- package/test/browser/test/plugin_browser_test_dom_parts.js +125 -125
- package/test/browser/test/plugin_browser_test_system.js +9 -9
- package/test/browser/test/plugin_turtle_test.js +817 -817
- package/test/browser/test/plugin_webworker_test.js +86 -86
- package/test/browser/test/require_test.js +68 -68
- package/test/bundled/karma.config.base.js +117 -117
- package/test/bundled/karma.config.js +86 -86
- package/test/bundled/test/.babelrc.json +3 -3
- package/test/bundled/test/bundled_test.js +69 -69
- package/test/bundled/test/html/custom_context.html +65 -65
- package/test/bundled/test/html/custom_debug.html +66 -66
- package/test/bundled/test4b.cmd +52 -52
- package/test/bundled/test_base/.babelrc.json +3 -3
- package/test/bundled/test_base/_checktool_test.js +25 -25
- package/test/bundled/test_base/basic_ajax_test.js +56 -56
- package/test/bundled/test_base/basic_async_test.js +18 -18
- package/test/bundled/test_base/basic_test.js +153 -153
- package/test/bundled/test_base/calc_test.js +132 -132
- package/test/bundled/test_base/css/browsers_box.css +114 -114
- package/test/bundled/test_base/html/custom_context.html +69 -69
- package/test/bundled/test_base/html/custom_debug.html +71 -71
- package/test/bundled/test_base/js/browsers_box.js +72 -72
- package/test/bundled/test_base/plugin_csv_test.js +37 -37
- package/test/bundled/test_base/plugin_datetime_test.js +115 -115
- package/test/bundled/test_base/plugin_kansuji_test.js +49 -49
- package/test/bundled/test_base/plugin_system_test.js +410 -410
- package/test/bundled/test_base/plugin_webworker_test.js +53 -53
- package/test/bundled/test_base/test_utils.js +191 -191
- package/test/common/plugin_browser_test.mjs +22 -24
- package/test/common/plugin_browser_ut_audio_test.mjs +108 -108
- package/test/common/plugin_browser_ut_color_test.mjs +21 -21
- package/test/common/plugin_browser_ut_dialog_test.mjs +100 -100
- package/test/common/plugin_browser_ut_html_test.mjs +13 -13
- package/test/common/plugin_browser_ut_system_test.mjs +10 -10
- package/test/common/plugin_markup_test.mjs +23 -23
- package/test/jsconfig.json +19 -19
- package/test/karma.config.js +91 -91
- package/test/node/async_test.mjs +96 -82
- package/test/node/commander_ja_test.mjs +89 -89
- package/test/node/error_message_test.mjs +243 -253
- package/test/node/kai_test.nako3 +6 -6
- package/test/node/node_test.mjs +60 -60
- package/test/node/plugin_broken.js.txt +3 -3
- package/test/node/plugin_browser_ut_ajax_test.mjs.todo +357 -357
- package/test/node/plugin_browser_ut_location_test.mjs +42 -42
- package/test/node/plugin_markup_test.mjs +47 -46
- package/test/node/plugin_math_test.mjs +45 -44
- package/test/node/plugin_node_test.mjs +98 -97
- package/test/node/plugin_test.mjs +44 -43
- package/test/node/relative_import_test_1.nako3 +1 -1
- package/test/node/relative_import_test_2.nako3 +2 -2
- package/test/node/require_nako3_test.mjs +67 -66
- package/test/node/requiretest.nako3 +4 -4
- package/test/node/requiretest_indirect.nako3 +1 -1
- package/test/node/requiretest_name.nako3 +5 -5
- package/test/node/runtime_error.nako3 +2 -2
- package/test/node/scope1.nako3 +10 -10
- package/test/node/scope2.nako3 +12 -12
- package/test/node/side_effects_test.mjs +39 -119
- package/test/node/sjis.txt +5 -5
- package/test/node/syntax_error.nako3 +1 -1
- package/test/node/wnako3_editor_test.mjs +384 -384
- package/tools/README.md +12 -7
- package/tools/check_new_version.nako3 +25 -25
- package/tools/nako3edit/html/daisyui/LICENSE +22 -22
- package/tools/nako3edit/html/daisyui/version_2.14.1 +1 -1
- package/tools/nako3edit/html/edit.html +170 -170
- package/tools/nako3edit/html/edit_plugin.js +6 -6
- package/tools/nako3edit/html/files.html +125 -125
- package/tools/nako3edit/html/nako3edit.css +65 -65
- package/tools/nako3edit/index.mjs +248 -244
- package/tools/nako3server/index.html +10 -0
- package/tools/nako3server/index.mjs +116 -116
- package/tools/nako3server/index.nako3 +34 -0
- package/release/nako_gen_async.js.LICENSE.txt +0 -35
- package/release/plugin_caniuse.js.LICENSE.txt +0 -11
- package/release/plugin_csv.js.LICENSE.txt +0 -15
- package/release/plugin_datetime.js.LICENSE.txt +0 -15
- package/release/plugin_kansuji.js.LICENSE.txt +0 -3
- package/release/plugin_markup.js.LICENSE.txt +0 -11
- package/release/plugin_turtle.js.LICENSE.txt +0 -15
- package/release/plugin_webworker.js.LICENSE.txt +0 -3
- package/release/plugin_weykturtle3d.js.LICENSE.txt +0 -3
- package/release/wnako3webworker.js.LICENSE.txt +0 -131
- package/tools/nako3edit/a.sqlite3 +0 -0
package/src/cnako3mod.mjs
CHANGED
|
@@ -1,687 +1,707 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* コマンドライン版のなでしこ3をモジュールとして定義
|
|
3
|
-
* 実際には cnako3.mjs から読み込まれる
|
|
4
|
-
*/
|
|
5
|
-
import fs from 'fs';
|
|
6
|
-
import fse from 'fs-extra';
|
|
7
|
-
import { exec } from 'child_process';
|
|
8
|
-
import path from 'path';
|
|
9
|
-
import { NakoCompiler } from '
|
|
10
|
-
import { NakoImportError } from '
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
this.
|
|
26
|
-
this.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
g.__varslist[0]['
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
.
|
|
47
|
-
.
|
|
48
|
-
.
|
|
49
|
-
.option('-
|
|
50
|
-
.option('-
|
|
51
|
-
.option('-
|
|
52
|
-
.option('-
|
|
53
|
-
.option('-
|
|
54
|
-
.option('-
|
|
55
|
-
.option('-
|
|
56
|
-
.option('-
|
|
57
|
-
.option('-
|
|
58
|
-
.option('-
|
|
59
|
-
.option('-
|
|
60
|
-
.option('-
|
|
61
|
-
.option('-
|
|
62
|
-
.option('-
|
|
63
|
-
|
|
64
|
-
// .option('-
|
|
65
|
-
.
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
args.
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
const
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
fs.
|
|
219
|
-
}
|
|
220
|
-
// from
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
const
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
const
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
//
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
.
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
})
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
this.
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
*
|
|
544
|
-
* @
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
* @param {string}
|
|
573
|
-
* @
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
if (
|
|
590
|
-
return
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
return
|
|
610
|
-
}
|
|
611
|
-
//
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
const
|
|
616
|
-
if (
|
|
617
|
-
return
|
|
618
|
-
}
|
|
619
|
-
return ''; //
|
|
620
|
-
}
|
|
621
|
-
//
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
}
|
|
676
|
-
//
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
1
|
+
/**
|
|
2
|
+
* コマンドライン版のなでしこ3をモジュールとして定義
|
|
3
|
+
* 実際には cnako3.mjs から読み込まれる
|
|
4
|
+
*/
|
|
5
|
+
import fs from 'fs';
|
|
6
|
+
import fse from 'fs-extra';
|
|
7
|
+
import { exec } from 'child_process';
|
|
8
|
+
import path from 'path';
|
|
9
|
+
import { NakoCompiler } from '../core/src/nako3.mjs';
|
|
10
|
+
import { NakoImportError } from '../core/src/nako_errors.mjs';
|
|
11
|
+
import { CompilerOptions } from '../core/src/nako_types.mjs';
|
|
12
|
+
import nakoVersion from './nako_version.mjs';
|
|
13
|
+
import PluginNode from './plugin_node.mjs';
|
|
14
|
+
import app from './commander_ja.mjs';
|
|
15
|
+
import fetch from 'node-fetch';
|
|
16
|
+
import { NakoGenOptions } from '../core/src/nako_gen.mjs';
|
|
17
|
+
// __dirname のために
|
|
18
|
+
import url from 'url';
|
|
19
|
+
const __filename = url.fileURLToPath(import.meta.url);
|
|
20
|
+
const __dirname = path.dirname(__filename);
|
|
21
|
+
/** CNako3 */
|
|
22
|
+
export class CNako3 extends NakoCompiler {
|
|
23
|
+
constructor(opts = { nostd: false }) {
|
|
24
|
+
super({ useBasicPlugin: !opts.nostd });
|
|
25
|
+
this.debug = false;
|
|
26
|
+
this.filename = 'main.nako3';
|
|
27
|
+
this.version = nakoVersion.version;
|
|
28
|
+
if (!opts.nostd) {
|
|
29
|
+
this.addPluginFile('PluginNode', path.join(__dirname, 'plugin_node.mjs'), PluginNode);
|
|
30
|
+
}
|
|
31
|
+
// 必要な定数を設定
|
|
32
|
+
this.addListener('beforeRun', (g) => {
|
|
33
|
+
g.__varslist[0]['ナデシコ種類'] = 'cnako3';
|
|
34
|
+
g.__varslist[0]['ナデシコバージョン'] = this.version;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
// CNAKO3で使えるコマンドを登録する
|
|
38
|
+
registerCommands() {
|
|
39
|
+
// コマンド引数がないならば、ヘルプを表示(-hはcommandarにデフォルト用意されている)
|
|
40
|
+
if (process.argv.length <= 2) {
|
|
41
|
+
process.argv.push('-h');
|
|
42
|
+
}
|
|
43
|
+
const verInfo = `v${nakoVersion.version}`;
|
|
44
|
+
// commanderを使って引数を解析する
|
|
45
|
+
app
|
|
46
|
+
.title('日本語プログラミング言語「なでしこ」' + verInfo)
|
|
47
|
+
.version(verInfo, '-v, --version')
|
|
48
|
+
.usage('[オプション] 入力ファイル.nako3')
|
|
49
|
+
.option('-h, --help', 'コマンドの使い方を表示')
|
|
50
|
+
.option('-w, --warn', '警告を表示する')
|
|
51
|
+
.option('-d, --debug', 'デバッグモードの指定')
|
|
52
|
+
.option('-D, --trace', '詳細デバッグモードの指定')
|
|
53
|
+
.option('-c, --compile', 'コンパイルモードの指定')
|
|
54
|
+
.option('-t, --test', 'コンパイルモードの指定 (テスト用コードを出力)')
|
|
55
|
+
.option('-r, --run', 'コンパイルモードでも実行する')
|
|
56
|
+
.option('-e, --eval [src]', '直接プログラムを実行するワンライナーモード')
|
|
57
|
+
.option('-o, --output', '出力ファイル名の指定')
|
|
58
|
+
.option('-s, --silent', 'サイレントモードの指定')
|
|
59
|
+
.option('-l, --repl', '対話シェル(REPL)の実行')
|
|
60
|
+
.option('-b, --browsers', '対応機器/Webブラウザを表示する')
|
|
61
|
+
.option('-m, --man [command]', 'マニュアルを表示する')
|
|
62
|
+
.option('-p, --speed', 'スピード優先モードの指定')
|
|
63
|
+
.option('-A, --ast', 'パースした結果をASTで出力する')
|
|
64
|
+
// .option('-h, --help', '使い方を表示する')
|
|
65
|
+
// .option('-v, --version', 'バージョンを表示する')
|
|
66
|
+
.parse(process.argv);
|
|
67
|
+
return app;
|
|
68
|
+
}
|
|
69
|
+
/** コマンドライン引数を解析 */
|
|
70
|
+
checkArguments() {
|
|
71
|
+
const app = this.registerCommands();
|
|
72
|
+
let logLevel = 'error';
|
|
73
|
+
if (app.trace) {
|
|
74
|
+
logLevel = 'trace';
|
|
75
|
+
}
|
|
76
|
+
else if (app.debug) {
|
|
77
|
+
logLevel = 'debug';
|
|
78
|
+
}
|
|
79
|
+
else if (app.warn) {
|
|
80
|
+
logLevel = 'warn';
|
|
81
|
+
}
|
|
82
|
+
this.getLogger().addListener(logLevel, ({ level, nodeConsole }) => {
|
|
83
|
+
console.log(nodeConsole);
|
|
84
|
+
});
|
|
85
|
+
const args = {
|
|
86
|
+
compile: app.compile || false,
|
|
87
|
+
run: app.run || false,
|
|
88
|
+
source: app.eval || '',
|
|
89
|
+
man: app.man || '',
|
|
90
|
+
one_liner: app.eval || false,
|
|
91
|
+
debug: this.debug || false,
|
|
92
|
+
trace: app.trace,
|
|
93
|
+
warn: app.warn,
|
|
94
|
+
repl: app.repl || false,
|
|
95
|
+
test: app.test || false,
|
|
96
|
+
browsers: app.browsers || false,
|
|
97
|
+
speed: app.speed || false,
|
|
98
|
+
ast: app.ast || false
|
|
99
|
+
};
|
|
100
|
+
args.mainfile = app.args[0];
|
|
101
|
+
args.output = app.output;
|
|
102
|
+
// todo: ESModule 対応の '.mjs' のコードを吐くように修正 #1217
|
|
103
|
+
const ext = '.mjs';
|
|
104
|
+
if (/\.(nako|nako3|txt|bak)$/.test(args.mainfile)) {
|
|
105
|
+
if (!args.output) {
|
|
106
|
+
if (args.test) {
|
|
107
|
+
args.output = args.mainfile.replace(/\.(nako|nako3)$/, '.spec' + ext);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
args.output = args.mainfile.replace(/\.(nako|nako3)$/, ext);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
if (!args.output) {
|
|
116
|
+
if (args.test) {
|
|
117
|
+
args.output = args.mainfile + '.spec' + ext;
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
args.output = args.mainfile + ext;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
args.mainfile += '.nako3';
|
|
124
|
+
}
|
|
125
|
+
return args;
|
|
126
|
+
}
|
|
127
|
+
// 実行する
|
|
128
|
+
async execCommand() {
|
|
129
|
+
// コマンドを解析
|
|
130
|
+
const opt = this.checkArguments();
|
|
131
|
+
// 使い方の表示か?
|
|
132
|
+
if (opt.man) {
|
|
133
|
+
this.cnakoMan(opt.man);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
// 対応ブラウザを表示する
|
|
137
|
+
if (opt.browsers) {
|
|
138
|
+
this.cnakoBrowsers();
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
// REPLを実行する
|
|
142
|
+
if (opt.repl) {
|
|
143
|
+
this.cnakoRepl(opt);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
// ワンライナーで実行する
|
|
147
|
+
if (opt.one_liner) {
|
|
148
|
+
this.cnakoOneLiner(opt);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
// メインプログラムを読み込む
|
|
152
|
+
this.filename = opt.mainfile;
|
|
153
|
+
const src = fs.readFileSync(opt.mainfile, 'utf-8');
|
|
154
|
+
if (opt.compile) {
|
|
155
|
+
await this.nakoCompile(opt, src, false);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
// ASTを出力する
|
|
159
|
+
if (opt.ast) {
|
|
160
|
+
try {
|
|
161
|
+
await this.loadDependencies(src, opt.mainfile, '');
|
|
162
|
+
}
|
|
163
|
+
catch (err) {
|
|
164
|
+
if (this.numFailures > 0) {
|
|
165
|
+
this.logger.error(err);
|
|
166
|
+
process.exit(1);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
this.outputAST(opt, src);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
// テストを実行する
|
|
173
|
+
if (opt.test) {
|
|
174
|
+
try {
|
|
175
|
+
await this.loadDependencies(src, opt.mainfile, '');
|
|
176
|
+
this.test(src, opt.mainfile);
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
catch (e) {
|
|
180
|
+
if (this.numFailures > 0) {
|
|
181
|
+
this.logger.error(e);
|
|
182
|
+
process.exit(1);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
// ファイルを読んで実行する
|
|
187
|
+
try {
|
|
188
|
+
// コンパイルと実行を行うメソッド
|
|
189
|
+
const g = await this.runAsync(src, opt.mainfile);
|
|
190
|
+
return g;
|
|
191
|
+
}
|
|
192
|
+
catch (e) {
|
|
193
|
+
this.logger.error(e);
|
|
194
|
+
// 文法エラーなどがあった場合
|
|
195
|
+
if (opt.debug || opt.trace) {
|
|
196
|
+
throw e;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* コンパイルモードの場合
|
|
202
|
+
* @param opt
|
|
203
|
+
* @param {string} src
|
|
204
|
+
* @param {boolean} isTest
|
|
205
|
+
*/
|
|
206
|
+
async nakoCompile(opt, src, isTest) {
|
|
207
|
+
// 依存ライブラリなどを読み込む
|
|
208
|
+
await this.loadDependencies(src, this.filename, '');
|
|
209
|
+
// JSにコンパイル
|
|
210
|
+
const genOpt = new NakoGenOptions(isTest, ['plugin_node.mjs'], 'self.__varslist[0][\'ナデシコ種類\']=\'cnako3\';');
|
|
211
|
+
const jscode = this.compileStandalone(src, this.filename, genOpt);
|
|
212
|
+
console.log(opt.output);
|
|
213
|
+
fs.writeFileSync(opt.output, jscode, 'utf-8');
|
|
214
|
+
// 実行に必要なファイルをコピー
|
|
215
|
+
const nakoRuntime = __dirname;
|
|
216
|
+
const outRuntime = path.join(path.dirname(opt.output), 'nako3runtime');
|
|
217
|
+
if (!fs.existsSync(outRuntime)) {
|
|
218
|
+
fs.mkdirSync(outRuntime);
|
|
219
|
+
}
|
|
220
|
+
// from ./src
|
|
221
|
+
for (const mod of ['nako_version.mjs', 'plugin_node.mjs']) {
|
|
222
|
+
fs.copyFileSync(path.join(nakoRuntime, mod), path.join(outRuntime, mod));
|
|
223
|
+
}
|
|
224
|
+
// from nadesiko3core/src
|
|
225
|
+
const srcDir = path.join(__dirname, '..', 'node_modules', 'nadesiko3core', 'src');
|
|
226
|
+
const baseFiles = ['nako_errors.mjs', 'nako_core_version.mjs',
|
|
227
|
+
'plugin_system.mjs', 'plugin_math.mjs', 'plugin_promise.mjs', 'plugin_test.mjs', 'plugin_csv.mjs', 'nako_csv.mjs'];
|
|
228
|
+
for (const mod of baseFiles) {
|
|
229
|
+
fs.copyFileSync(path.join(srcDir, mod), path.join(outRuntime, mod));
|
|
230
|
+
}
|
|
231
|
+
// or 以下のコピーだと依存ファイルがコピーされない package.jsonを見てコピーする必要がある
|
|
232
|
+
const orgModule = path.join(__dirname, '..', 'node_modules');
|
|
233
|
+
const dirNodeModules = path.join(path.dirname(opt.output), 'node_modules');
|
|
234
|
+
const modlist = ['fs-extra', 'iconv-lite', 'opener', 'node-fetch'];
|
|
235
|
+
const copied = {};
|
|
236
|
+
// 再帰的に必要なモジュールをコピーする
|
|
237
|
+
const copyModule = (mod) => {
|
|
238
|
+
if (copied[mod]) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
copied[mod] = true;
|
|
242
|
+
// ライブラリ自身をコピー
|
|
243
|
+
fse.copySync(path.join(orgModule, mod), path.join(dirNodeModules, mod));
|
|
244
|
+
// 依存ライブラリをコピー
|
|
245
|
+
const packageFile = path.join(orgModule, mod, 'package.json');
|
|
246
|
+
const jsonStr = fs.readFileSync(packageFile, 'utf-8');
|
|
247
|
+
const jsonData = JSON.parse(jsonStr);
|
|
248
|
+
// サブモジュールをコピー
|
|
249
|
+
for (const smod in jsonData.dependencies) {
|
|
250
|
+
copyModule(smod);
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
for (const mod of modlist) {
|
|
254
|
+
copyModule(mod);
|
|
255
|
+
}
|
|
256
|
+
if (opt.run) {
|
|
257
|
+
exec(`node ${opt.output}`, function (err, stdout, stderr) {
|
|
258
|
+
if (err) {
|
|
259
|
+
console.log('[ERROR]', stderr);
|
|
260
|
+
}
|
|
261
|
+
console.log(stdout);
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
// ワンライナーの場合
|
|
266
|
+
async cnakoOneLiner(opt) {
|
|
267
|
+
const org = opt.source;
|
|
268
|
+
try {
|
|
269
|
+
if (opt.source.indexOf('表示') < 0) {
|
|
270
|
+
opt.source = '' + opt.source + 'を表示。';
|
|
271
|
+
}
|
|
272
|
+
await this.runAsync(opt.source, 'main.nako3');
|
|
273
|
+
}
|
|
274
|
+
catch (e) {
|
|
275
|
+
// エラーになったら元のワンライナーで再挑戦
|
|
276
|
+
try {
|
|
277
|
+
if (opt.source !== org) {
|
|
278
|
+
await this.runAsync(org, 'main.nako3');
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
throw e;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
catch (e) {
|
|
285
|
+
if (this.debug) {
|
|
286
|
+
throw e;
|
|
287
|
+
}
|
|
288
|
+
else {
|
|
289
|
+
console.error(e.message);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* ASTを出力
|
|
296
|
+
* @param opt
|
|
297
|
+
* @param {string} src
|
|
298
|
+
*/
|
|
299
|
+
outputAST(opt, src) {
|
|
300
|
+
const ast = this.parse(src, opt.mainfile);
|
|
301
|
+
const makeIndent = (level) => {
|
|
302
|
+
let s = '';
|
|
303
|
+
for (let i = 0; i < level; i++) {
|
|
304
|
+
s += ' ';
|
|
305
|
+
}
|
|
306
|
+
return s;
|
|
307
|
+
};
|
|
308
|
+
const trim = (s) => { return s.replace(/(^\s+|\s+$)/g, ''); };
|
|
309
|
+
/**
|
|
310
|
+
* AST文字列に変換して返す
|
|
311
|
+
* @param {*} ast
|
|
312
|
+
* @param {number} level
|
|
313
|
+
* @return {string}
|
|
314
|
+
*/
|
|
315
|
+
const outAST = (ast, level) => {
|
|
316
|
+
if (typeof (ast) === 'string') {
|
|
317
|
+
return makeIndent(level) + '"' + ast + '"';
|
|
318
|
+
}
|
|
319
|
+
if (typeof (ast) === 'number') {
|
|
320
|
+
return makeIndent(level) + ast;
|
|
321
|
+
}
|
|
322
|
+
if (ast instanceof Array) {
|
|
323
|
+
const s = makeIndent(level) + '[\n';
|
|
324
|
+
const sa = [];
|
|
325
|
+
ast.forEach((a) => {
|
|
326
|
+
sa.push(outAST(a, level + 1));
|
|
327
|
+
});
|
|
328
|
+
return s + sa.join(',\n') + '\n' + makeIndent(level) + ']';
|
|
329
|
+
}
|
|
330
|
+
if (ast instanceof Object) {
|
|
331
|
+
const s = makeIndent(level) + '{\n';
|
|
332
|
+
const sa = [];
|
|
333
|
+
for (const key in ast) {
|
|
334
|
+
const sv = trim(outAST(ast[key], level + 1));
|
|
335
|
+
const so = makeIndent(level + 1) + '"' + key + '": ' + sv;
|
|
336
|
+
sa.push(so);
|
|
337
|
+
}
|
|
338
|
+
return s + sa.join(',\n') + '\n' + makeIndent(level) + '}';
|
|
339
|
+
}
|
|
340
|
+
return makeIndent(level) + ast;
|
|
341
|
+
};
|
|
342
|
+
console.log(outAST(ast, 0));
|
|
343
|
+
}
|
|
344
|
+
// REPL(対話実行環境)の場合
|
|
345
|
+
async cnakoRepl(_opt) {
|
|
346
|
+
const fname = path.join(__dirname, 'repl.nako3');
|
|
347
|
+
const src = fs.readFileSync(fname, 'utf-8');
|
|
348
|
+
await this.runAsync(src, 'main.nako3');
|
|
349
|
+
}
|
|
350
|
+
// マニュアルを表示する
|
|
351
|
+
cnakoMan(command) {
|
|
352
|
+
try {
|
|
353
|
+
const pathCommands = path.join(__dirname, '../release/command_cnako3.json');
|
|
354
|
+
const commands = JSON.parse(fs.readFileSync(pathCommands, 'utf-8'));
|
|
355
|
+
const data = commands[command];
|
|
356
|
+
for (const key in data) {
|
|
357
|
+
console.log(`${key}: ${data[key]}`);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
catch (e) {
|
|
361
|
+
if (e.code === 'MODULE_NOT_FOUND') {
|
|
362
|
+
console.log('コマンド一覧がないため、マニュアルを表示できません。以下のコマンドでコマンド一覧を生成してください。\n$ npm run build');
|
|
363
|
+
}
|
|
364
|
+
else {
|
|
365
|
+
throw e;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
// 対応機器/Webブラウザを表示する
|
|
370
|
+
cnakoBrowsers() {
|
|
371
|
+
const fileMD = path.resolve(__dirname, '../doc', 'browsers.md');
|
|
372
|
+
console.log(fs.readFileSync(fileMD, 'utf-8'));
|
|
373
|
+
}
|
|
374
|
+
// (js|nako3) loader
|
|
375
|
+
getLoaderTools() {
|
|
376
|
+
/** @type {string[]} */
|
|
377
|
+
const log = [];
|
|
378
|
+
const tools = {
|
|
379
|
+
resolvePath: (name, token, fromFile) => {
|
|
380
|
+
// 最初に拡張子があるかどうかをチェック
|
|
381
|
+
// JSプラグインか?
|
|
382
|
+
if (/\.(js|mjs)(\.txt)?$/.test(name)) {
|
|
383
|
+
const jspath = CNako3.findJSPluginFile(name, fromFile, __dirname, log);
|
|
384
|
+
if (jspath === '') {
|
|
385
|
+
throw new NakoImportError(`JSプラグイン『${name}』が見つかりません。以下のパスを検索しました。\n${log.join('\n')}`, token.file, token.line);
|
|
386
|
+
}
|
|
387
|
+
return { filePath: jspath, type: 'js' };
|
|
388
|
+
}
|
|
389
|
+
// なでしこプラグインか?
|
|
390
|
+
if (/\.(nako3|nako)(\.txt)?$/.test(name)) {
|
|
391
|
+
// ファイルかHTTPか
|
|
392
|
+
if (name.startsWith('http://') || name.startsWith('https://')) {
|
|
393
|
+
return { filePath: name, type: 'nako3' };
|
|
394
|
+
}
|
|
395
|
+
if (path.isAbsolute(name)) {
|
|
396
|
+
return { filePath: path.resolve(name), type: 'nako3' };
|
|
397
|
+
}
|
|
398
|
+
else {
|
|
399
|
+
// filename が undefined のとき token.file が undefined になる。
|
|
400
|
+
if (token.file === undefined) {
|
|
401
|
+
throw new Error('ファイル名を指定してください。');
|
|
402
|
+
}
|
|
403
|
+
const dir = path.dirname(fromFile);
|
|
404
|
+
return { filePath: path.resolve(path.join(dir, name)), type: 'nako3' };
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
// 拡張子がない、あるいは、(.js|.mjs|.nako3|.nako)以外はJSモジュールと見なす
|
|
408
|
+
const jspath2 = CNako3.findJSPluginFile(name, fromFile, __dirname, log);
|
|
409
|
+
if (jspath2 === '') {
|
|
410
|
+
throw new NakoImportError(`JSプラグイン『${name}』が見つかりません。以下のパスを検索しました。\n${log.join('\n')}`, token.file, token.line);
|
|
411
|
+
}
|
|
412
|
+
return { filePath: jspath2, type: 'js' };
|
|
413
|
+
},
|
|
414
|
+
readNako3: (name, token) => {
|
|
415
|
+
const loader = { task: null };
|
|
416
|
+
// ファイルかHTTPか
|
|
417
|
+
if (name.startsWith('http://') || name.startsWith('https://')) {
|
|
418
|
+
// Webのファイルを非同期で読み込む
|
|
419
|
+
loader.task = (async () => {
|
|
420
|
+
const res = await fetch(name);
|
|
421
|
+
if (!res.ok) {
|
|
422
|
+
throw new NakoImportError(`『${name}』からのダウンロードに失敗しました: ${res.status} ${res.statusText}`, token.file, token.line);
|
|
423
|
+
}
|
|
424
|
+
return await res.text();
|
|
425
|
+
})();
|
|
426
|
+
}
|
|
427
|
+
else {
|
|
428
|
+
// ファイルを非同期で読み込む
|
|
429
|
+
// ファイルチェックだけ先に実行
|
|
430
|
+
if (!fs.existsSync(name)) {
|
|
431
|
+
throw new NakoImportError(`ファイル ${name} が存在しません。`, token.file, token.line);
|
|
432
|
+
}
|
|
433
|
+
loader.task = (new Promise((resolve, reject) => {
|
|
434
|
+
fs.readFile(name, { encoding: 'utf-8' }, (err, data) => {
|
|
435
|
+
if (err) {
|
|
436
|
+
return reject(err);
|
|
437
|
+
}
|
|
438
|
+
resolve(data);
|
|
439
|
+
});
|
|
440
|
+
}));
|
|
441
|
+
}
|
|
442
|
+
// 非同期で読み込む
|
|
443
|
+
return loader;
|
|
444
|
+
},
|
|
445
|
+
readJs: (filePath, token) => {
|
|
446
|
+
const loader = { task: null };
|
|
447
|
+
if (process.platform === 'win32') {
|
|
448
|
+
if (filePath.substring(1, 3) === ':\\') {
|
|
449
|
+
filePath = 'file://' + filePath;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
// URLからの読み取り
|
|
453
|
+
// ファイルかHTTPか
|
|
454
|
+
if (filePath.startsWith('http://') || filePath.startsWith('https://')) {
|
|
455
|
+
// 動的 import が http 未対応のため、一度、Webのファイルを非同期で読み込んで/tmpに保存してから動的importを行う
|
|
456
|
+
loader.task = (new Promise((resolve, reject) => {
|
|
457
|
+
// 一時フォルダを得る
|
|
458
|
+
const osTmpDir = (process.platform === 'win32') ? process.env.TEMP : '/tmp';
|
|
459
|
+
const osTmpDir2 = (osTmpDir) || path.join('./tmp');
|
|
460
|
+
const tmpDir = path.join(osTmpDir2, 'com.nadesi.v3.cnako');
|
|
461
|
+
const tmpFile = path.join(tmpDir, filePath.replace(/[^a-zA-Z0-9_.]/g, '_'));
|
|
462
|
+
if (!fs.existsSync(tmpDir)) {
|
|
463
|
+
fs.mkdirSync(tmpDir, { recursive: true });
|
|
464
|
+
}
|
|
465
|
+
// WEBからダウンロード
|
|
466
|
+
fetch(filePath)
|
|
467
|
+
.then((res) => {
|
|
468
|
+
return res.text();
|
|
469
|
+
})
|
|
470
|
+
.then((txt) => {
|
|
471
|
+
// 一時ファイルに保存
|
|
472
|
+
try {
|
|
473
|
+
fs.writeFileSync(tmpFile, txt, 'utf-8');
|
|
474
|
+
}
|
|
475
|
+
catch (err) {
|
|
476
|
+
const err2 = new NakoImportError(`URL『${filePath}』からダウンロードしたJSファイルがキャッシュに書き込めません。${err}`, token.file, token.line);
|
|
477
|
+
reject(err2);
|
|
478
|
+
}
|
|
479
|
+
})
|
|
480
|
+
.then(() => {
|
|
481
|
+
// 一時ファイルから読み込む
|
|
482
|
+
import(tmpFile).then((mod) => {
|
|
483
|
+
// プラグインは export default で宣言
|
|
484
|
+
const obj = Object.assign({}, mod);
|
|
485
|
+
resolve(() => {
|
|
486
|
+
return obj.default;
|
|
487
|
+
});
|
|
488
|
+
}).catch((err) => {
|
|
489
|
+
const err2 = new NakoImportError(`URL『${filePath}』からダウンロードしたはずのJSファイル読み込めません。${err}`, token.file, token.line);
|
|
490
|
+
reject(err2);
|
|
491
|
+
});
|
|
492
|
+
})
|
|
493
|
+
.catch((err) => {
|
|
494
|
+
const err2 = new NakoImportError(`URL『${filePath}』からJSファイルが読み込めません。${err}`, token.file, token.line);
|
|
495
|
+
reject(err2);
|
|
496
|
+
});
|
|
497
|
+
}));
|
|
498
|
+
return loader;
|
|
499
|
+
}
|
|
500
|
+
loader.task = (new Promise((resolve, reject) => {
|
|
501
|
+
import(filePath).then((mod) => {
|
|
502
|
+
// プラグインは export default で宣言
|
|
503
|
+
const obj = Object.assign({}, mod);
|
|
504
|
+
resolve(() => { return obj.default; });
|
|
505
|
+
}).catch((err) => {
|
|
506
|
+
const err2 = new NakoImportError(`ファイル『${filePath}』が読み込めません。${err}`, token.file, token.line);
|
|
507
|
+
reject(err2);
|
|
508
|
+
});
|
|
509
|
+
}));
|
|
510
|
+
return loader;
|
|
511
|
+
}
|
|
512
|
+
};
|
|
513
|
+
return tools;
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* @param {string} code
|
|
517
|
+
* @param {string} filename
|
|
518
|
+
* @param {string} preCode
|
|
519
|
+
* @returns {Promise<void>}
|
|
520
|
+
*/
|
|
521
|
+
async loadDependencies(code, filename, preCode) {
|
|
522
|
+
const tools = this.getLoaderTools();
|
|
523
|
+
await super._loadDependencies(code, filename, preCode, tools);
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* @param code
|
|
527
|
+
* @param fname
|
|
528
|
+
* @param [preCode]
|
|
529
|
+
*/
|
|
530
|
+
async runAsync(code, fname, options = new CompilerOptions()) {
|
|
531
|
+
// 取り込む文の処理
|
|
532
|
+
try {
|
|
533
|
+
await this.loadDependencies(code, fname, options.preCode);
|
|
534
|
+
}
|
|
535
|
+
catch (err) {
|
|
536
|
+
// 読み込みエラーは報告のみして続けて実行してみる
|
|
537
|
+
this.getLogger().error(err);
|
|
538
|
+
}
|
|
539
|
+
// 実行
|
|
540
|
+
return super.runAsync(code, fname, options);
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* プラグインファイルの検索を行う
|
|
544
|
+
* @param {string} pname プラグインの名前
|
|
545
|
+
* @param {string} filename 取り込み元ファイル名
|
|
546
|
+
* @param {string} srcDir このファイルが存在するディレクトリ
|
|
547
|
+
* @param {string[]} [log]
|
|
548
|
+
* @return {string} フルパス、失敗した時は、''を返す
|
|
549
|
+
*/
|
|
550
|
+
static findJSPluginFile(pname, filename, srcDir, log = []) {
|
|
551
|
+
log.length = 0;
|
|
552
|
+
const cachePath = {};
|
|
553
|
+
/** キャッシュ付きでファイルがあるか検索 */
|
|
554
|
+
const exists = (f) => {
|
|
555
|
+
// 同じパスを何度も検索することがないように
|
|
556
|
+
if (cachePath[f]) {
|
|
557
|
+
return cachePath[f];
|
|
558
|
+
}
|
|
559
|
+
try {
|
|
560
|
+
// ファイルがないと例外が出る
|
|
561
|
+
const stat = fs.statSync(f);
|
|
562
|
+
const b = !!(stat && stat.isFile());
|
|
563
|
+
cachePath[f] = b;
|
|
564
|
+
return b;
|
|
565
|
+
}
|
|
566
|
+
catch (err) {
|
|
567
|
+
return false;
|
|
568
|
+
}
|
|
569
|
+
};
|
|
570
|
+
/** 普通にファイルをチェック
|
|
571
|
+
* @param {string} pathTest
|
|
572
|
+
* @param {string} desc
|
|
573
|
+
* @returns {boolean}
|
|
574
|
+
*/
|
|
575
|
+
const fCheck = (pathTest, desc) => {
|
|
576
|
+
// 素直に指定されたパスをチェック
|
|
577
|
+
const bExists = exists(pathTest);
|
|
578
|
+
log.push(`- (${desc}) ${pathTest}, ${bExists}`);
|
|
579
|
+
return bExists;
|
|
580
|
+
};
|
|
581
|
+
/** 通常 + package.json のパスを調べる
|
|
582
|
+
* @param {string} pathTest
|
|
583
|
+
* @param {string} desc
|
|
584
|
+
* @returns {string}
|
|
585
|
+
*/
|
|
586
|
+
const fCheckEx = (pathTest, desc) => {
|
|
587
|
+
// 直接JSファイルが指定された?
|
|
588
|
+
if (/\.(js|mjs)$/.test(pathTest)) {
|
|
589
|
+
if (fCheck(pathTest, desc)) {
|
|
590
|
+
return pathTest;
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
// 指定パスのpackage.jsonを調べる
|
|
594
|
+
const json = path.join(pathTest, 'package.json');
|
|
595
|
+
if (fCheck(json, desc + '/package.json')) {
|
|
596
|
+
// package.jsonを見つけたので、メインファイルを調べて取り込む (CommonJSモジュール対策)
|
|
597
|
+
const jsonText = fs.readFileSync(json, 'utf-8');
|
|
598
|
+
const obj = JSON.parse(jsonText);
|
|
599
|
+
if (!obj.main) {
|
|
600
|
+
return '';
|
|
601
|
+
}
|
|
602
|
+
const mainFile = path.resolve(path.join(pathTest, obj.main));
|
|
603
|
+
return mainFile;
|
|
604
|
+
}
|
|
605
|
+
return '';
|
|
606
|
+
};
|
|
607
|
+
// URL指定か?
|
|
608
|
+
if (pname.substring(0, 8) === 'https://') {
|
|
609
|
+
return pname;
|
|
610
|
+
}
|
|
611
|
+
// 各パスを検索していく
|
|
612
|
+
const p1 = pname.substring(0, 1);
|
|
613
|
+
// フルパス指定か?
|
|
614
|
+
if (p1 === '/' || pname.substring(1, 3).toLowerCase() === ':\\' || pname.substring(0, 6) === 'file:/') {
|
|
615
|
+
const fileFullpath = fCheckEx(pname, 'フルパス');
|
|
616
|
+
if (fileFullpath) {
|
|
617
|
+
return fileFullpath;
|
|
618
|
+
}
|
|
619
|
+
return ''; // フルパスの場合別のフォルダは調べない
|
|
620
|
+
}
|
|
621
|
+
// 相対パスか?
|
|
622
|
+
if (p1 === '.' || pname.indexOf('/') >= 0) {
|
|
623
|
+
// 相対パス指定なので、なでしこのプログラムからの相対指定を調べる
|
|
624
|
+
const pathRelative = path.join(path.resolve(path.dirname(filename)), pname);
|
|
625
|
+
const fileRelative = fCheckEx(pathRelative, '相対パス');
|
|
626
|
+
if (fileRelative) {
|
|
627
|
+
return fileRelative;
|
|
628
|
+
}
|
|
629
|
+
return ''; // 相対パスの場合も別のフォルダは調べない
|
|
630
|
+
}
|
|
631
|
+
// plugin_xxx.mjs のようにファイル名のみが指定された場合のみ、いくつかのパスを調べる
|
|
632
|
+
// 母艦パス(元ファイルと同じフォルダ)か?
|
|
633
|
+
const testScriptPath = path.join(path.resolve(path.dirname(filename)), pname);
|
|
634
|
+
const fileScript = fCheckEx(testScriptPath, '母艦パス');
|
|
635
|
+
if (fileScript) {
|
|
636
|
+
return fileScript;
|
|
637
|
+
}
|
|
638
|
+
// ランタイムパス/src/<plugin>
|
|
639
|
+
if (pname.match(/^plugin_[a-z0-9_]+\.mjs/)) {
|
|
640
|
+
// cnako3mod.mjs は ランタイム/src に配置されていることが前提
|
|
641
|
+
const pathRoot = path.resolve(__dirname, '..');
|
|
642
|
+
const pathRuntimeSrc = path.join(pathRoot, 'src', pname);
|
|
643
|
+
const fileRuntimeSrc = fCheckEx(pathRuntimeSrc, 'CNAKO3パス');
|
|
644
|
+
if (fileRuntimeSrc) {
|
|
645
|
+
return fileRuntimeSrc;
|
|
646
|
+
}
|
|
647
|
+
// ランタイム/core/src/<plugin>
|
|
648
|
+
const pathCore = path.join(pathRoot, 'core', 'src', pname);
|
|
649
|
+
const fileCore = fCheckEx(pathCore, 'CNAKO3パス');
|
|
650
|
+
if (fileCore) {
|
|
651
|
+
return fileCore;
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
// 環境変数をチェック
|
|
655
|
+
// 環境変数 NAKO_LIB か?
|
|
656
|
+
if (process.env.NAKO_LIB) {
|
|
657
|
+
const NAKO_LIB = path.join(path.resolve(process.env.NAKO_LIB), pname);
|
|
658
|
+
const fileLib = fCheckEx(NAKO_LIB, 'NAKO_LIB');
|
|
659
|
+
if (fileLib) {
|
|
660
|
+
return fileLib;
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
// ランタイムパス/node_modules/<plugin>
|
|
664
|
+
const pathRuntime = path.join(path.dirname(path.resolve(__dirname)));
|
|
665
|
+
const pathRuntimePname = path.join(pathRuntime, 'node_modules', pname);
|
|
666
|
+
const fileRuntime = fCheckEx(pathRuntimePname, 'runtime');
|
|
667
|
+
if (fileRuntime) {
|
|
668
|
+
return fileRuntime;
|
|
669
|
+
}
|
|
670
|
+
// ランタイムと同じ配置 | ランタイムパス/../<plugin>
|
|
671
|
+
const runtimeLib = path.join(pathRuntime, '..', pname);
|
|
672
|
+
const fileLib = fCheckEx(runtimeLib, 'runtimeLib');
|
|
673
|
+
if (fileLib) {
|
|
674
|
+
return fileLib;
|
|
675
|
+
}
|
|
676
|
+
// nadesiko3core | ランタイムパス/node_modules/nadesiko3core/src/<plugin>
|
|
677
|
+
const pathRuntimeSrc2 = path.join(pathRuntime, 'node_modules', 'nadesiko3core', 'src', pname); // cnako3mod.mjs は ランタイム/src に配置されていることが前提
|
|
678
|
+
const fileRuntimeSrc2 = fCheckEx(pathRuntimeSrc2, 'nadesiko3core');
|
|
679
|
+
if (fileRuntimeSrc2) {
|
|
680
|
+
return fileRuntimeSrc2;
|
|
681
|
+
}
|
|
682
|
+
// 環境変数 NAKO_HOMEか?
|
|
683
|
+
if (process.env.NAKO_HOME) {
|
|
684
|
+
const NAKO_HOME = path.join(path.resolve(process.env.NAKO_HOME), 'node_modules', pname);
|
|
685
|
+
const fileHome = fCheckEx(NAKO_HOME, 'NAKO_HOME');
|
|
686
|
+
if (fileHome) {
|
|
687
|
+
return fileHome;
|
|
688
|
+
}
|
|
689
|
+
// NAKO_HOME/src ?
|
|
690
|
+
const pathNakoHomeSrc = path.join(NAKO_HOME, 'src', pname);
|
|
691
|
+
const fileNakoHomeSrc = fCheckEx(pathNakoHomeSrc, 'NAKO_HOME/src');
|
|
692
|
+
if (fileNakoHomeSrc) {
|
|
693
|
+
return fileNakoHomeSrc;
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
// 環境変数 NODE_PATH (global) 以下にあるか?
|
|
697
|
+
if (process.env.NODE_PATH) {
|
|
698
|
+
const pathNode = path.join(path.resolve(process.env.NODE_PATH), pname);
|
|
699
|
+
const fileNode = fCheckEx(pathNode, 'NODE_PATH');
|
|
700
|
+
if (fileNode) {
|
|
701
|
+
return fileNode;
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
// Nodeのパス検索には任せない(importで必ず失敗するので)
|
|
705
|
+
return '';
|
|
706
|
+
}
|
|
707
|
+
}
|