nadesiko3 3.3.13 → 3.3.16
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/README.md +12 -0
- package/demo/nako3/aaa/bbb/ccc.nako3 +2 -0
- package/demo/nako3/aaa/p1.nako3 +4 -0
- package/demo/nako3/aaa.nako3 +5 -0
- package/package.json +1 -1
- package/release/_hash.txt +8 -8
- package/release/_script-tags.txt +14 -14
- package/release/stats.json +1 -1
- package/release/version.js +1 -1
- package/release/wnako3.js +1 -1
- package/src/cnako3mod.mjs +143 -71
- package/src/nako3.mjs +19 -20
- package/src/nako_gen.mjs +25 -33
- package/src/nako_version.mjs +2 -2
- package/src/plugin_node.mjs +12 -10
- package/src/wnako3.mjs +53 -23
- package/tools/nako3edit/run.mjs +1 -1
package/src/wnako3.mjs
CHANGED
|
@@ -53,17 +53,15 @@ class WebNakoCompiler extends NakoCompiler {
|
|
|
53
53
|
// eslint-disable-next-line no-prototype-builtins
|
|
54
54
|
if (localFiles.hasOwnProperty(filePath)) {
|
|
55
55
|
return {
|
|
56
|
-
|
|
57
|
-
value: () => {
|
|
56
|
+
task: (async () => () => {
|
|
58
57
|
// eslint-disable-next-line no-new-func
|
|
59
58
|
Function(localFiles[filePath])()
|
|
60
59
|
return {}
|
|
61
|
-
}
|
|
60
|
+
})()
|
|
62
61
|
}
|
|
63
62
|
}
|
|
64
63
|
return {
|
|
65
|
-
|
|
66
|
-
value: (async () => {
|
|
64
|
+
task: (async () => {
|
|
67
65
|
const res = await fetch(filePath)
|
|
68
66
|
if (!res.ok) {
|
|
69
67
|
throw new NakoImportError(`ファイル『${filePath}』のダウンロードに失敗しました: ${res.status} ${res.statusText}`, token.file, token.line)
|
|
@@ -93,11 +91,10 @@ class WebNakoCompiler extends NakoCompiler {
|
|
|
93
91
|
readNako3: (filePath, token) => {
|
|
94
92
|
// eslint-disable-next-line no-prototype-builtins
|
|
95
93
|
if (localFiles.hasOwnProperty(filePath)) {
|
|
96
|
-
return {
|
|
94
|
+
return {task: (async () => { return localFiles[filePath] })}
|
|
97
95
|
}
|
|
98
96
|
return {
|
|
99
|
-
|
|
100
|
-
value: (async () => {
|
|
97
|
+
task: (async () => {
|
|
101
98
|
const res = await fetch(filePath)
|
|
102
99
|
if (!res.ok) {
|
|
103
100
|
throw new NakoImportError(`ファイル ${filePath} のダウンロードに失敗しました: ${res.status} ${res.statusText}`, token.file, token.line)
|
|
@@ -106,32 +103,42 @@ class WebNakoCompiler extends NakoCompiler {
|
|
|
106
103
|
})()
|
|
107
104
|
}
|
|
108
105
|
},
|
|
109
|
-
resolvePath: (name, token) => {
|
|
110
|
-
// ローカルにファイルが存在するならそれを使う。そうでなければURLとして解釈する。
|
|
106
|
+
resolvePath: (name, token, fromFile) => {
|
|
111
107
|
let pathname = name
|
|
112
|
-
//
|
|
113
|
-
if (
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
108
|
+
// http から始まっていれば解決は不要
|
|
109
|
+
if (pathname.startsWith('http://') || pathname.startsWith('https://')) {
|
|
110
|
+
// fullpath
|
|
111
|
+
} else {
|
|
112
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
113
|
+
// ローカルにファイルが存在するならそれを使う。そうでなければURLとして解釈する。
|
|
114
|
+
if (!localFiles.hasOwnProperty(name)) {
|
|
118
115
|
try {
|
|
119
|
-
|
|
120
|
-
const href_dir = href_a.splice(0, href_a.length - 1).join('/');
|
|
121
|
-
const href = href_dir + '/' + name
|
|
122
|
-
pathname = new URL(href).pathname
|
|
116
|
+
pathname = new URL(name).pathname
|
|
123
117
|
} catch (e) {
|
|
124
|
-
|
|
118
|
+
// 単純にパスに変換できなければ、loccation.hrefを参考にパスを組み立てる
|
|
119
|
+
try {
|
|
120
|
+
let baseDir = dirname(fromFile)
|
|
121
|
+
if (baseDir === '') {
|
|
122
|
+
// https://2/3/4.html
|
|
123
|
+
const a = window.location.href.split('/')
|
|
124
|
+
baseDir = '/' + a.slice(3,a.length - 1).join('/')
|
|
125
|
+
}
|
|
126
|
+
pathname = resolveURL(baseDir, name)
|
|
127
|
+
} catch (e) {
|
|
128
|
+
throw new NakoImportError(`取り込み文の引数でパスが解決できません。https:// か http:// で始まるアドレスを指定してください。\n${e}`, token.file, token.line)
|
|
129
|
+
}
|
|
125
130
|
}
|
|
131
|
+
} else {
|
|
132
|
+
pathname = localFiles[name]
|
|
126
133
|
}
|
|
127
134
|
}
|
|
128
135
|
// .js および .mjs なら JSプラグイン
|
|
129
136
|
if (pathname.endsWith('.js') || pathname.endsWith('.js.txt') || pathname.endsWith('.mjs') || pathname.endsWith('.mjs.txt')) {
|
|
130
|
-
return { filePath:
|
|
137
|
+
return { filePath: pathname, type: 'js' }
|
|
131
138
|
}
|
|
132
139
|
// .nako3 なら なでしこ3プラグイン
|
|
133
140
|
if (pathname.endsWith('.nako3') || pathname.endsWith('.nako3.txt')) {
|
|
134
|
-
return { filePath:
|
|
141
|
+
return { filePath: pathname, type: 'nako3' }
|
|
135
142
|
}
|
|
136
143
|
// ファイル拡張子が未指定の場合
|
|
137
144
|
throw new NakoImportError(`ファイル『${name}』は拡張子が(.nako3|.js|.js.txt|.mjs|.mjs.txt)以外なので取り込めません。`, token.file, token.line)
|
|
@@ -166,6 +173,29 @@ class WebNakoCompiler extends NakoCompiler {
|
|
|
166
173
|
}
|
|
167
174
|
}
|
|
168
175
|
|
|
176
|
+
function dirname(s) {
|
|
177
|
+
const a = s.split('/')
|
|
178
|
+
if (a && a.length > 1) {
|
|
179
|
+
return a.slice(0, a.length - 1).join('/')
|
|
180
|
+
}
|
|
181
|
+
return ''
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function resolveURL(base, s) {
|
|
185
|
+
const baseA = base.split('/')
|
|
186
|
+
const sA = s.split('/')
|
|
187
|
+
for (let p of sA) {
|
|
188
|
+
if (p === '') {continue}
|
|
189
|
+
if (p === '.') {continue}
|
|
190
|
+
if (p === '..') {
|
|
191
|
+
baseA.pop()
|
|
192
|
+
continue
|
|
193
|
+
}
|
|
194
|
+
baseA.push(p)
|
|
195
|
+
}
|
|
196
|
+
return baseA.join('/')
|
|
197
|
+
}
|
|
198
|
+
|
|
169
199
|
// ブラウザなら navigator.nako3 になでしこを登録
|
|
170
200
|
if (typeof (navigator) === 'object' && !navigator.exportWNako3) {
|
|
171
201
|
const nako3 = navigator.nako3 = new WebNakoCompiler()
|
package/tools/nako3edit/run.mjs
CHANGED
|
@@ -9,7 +9,7 @@ const __filename = url.fileURLToPath(import.meta.url);
|
|
|
9
9
|
const __dirname = path.dirname(__filename);
|
|
10
10
|
|
|
11
11
|
const nakoHome = path.resolve(path.join(__dirname, '../../'))
|
|
12
|
-
const cnako3 = path.resolve(path.join(nakoHome, 'src/cnako3.
|
|
12
|
+
const cnako3 = path.resolve(path.join(nakoHome, 'src/cnako3.mjs'))
|
|
13
13
|
const nako3edit = path.resolve(path.join(__dirname, 'index.nako3'))
|
|
14
14
|
|
|
15
15
|
let proc = spawn('node', [cnako3, nako3edit])
|