FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
msgpack-javascript/tools/fix-ext.mts at main · msgpack/msgpack-javascript · GitHub
msgpack
/
msgpack-javascript
Public
Notifications
You must be signed in to change notification settings
Fork
180
Star
1.6k
Code
Issues
19
Pull requests
5
Discussions
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
msgpack-javascript
/
tools
/
fix-ext.mts
Copy path
More file actions
More file actions
Latest commit
History
History
History
42 lines (37 loc) · 1.75 KB
Breadcrumbs
msgpack-javascript
/
tools
/
fix-ext.mts
Copy path
File metadata and controls
42 lines (37 loc) · 1.75 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import
fs
from
"node:fs"
;
const
mode
=
process
.
argv
[
2
]
;
// --cjs or --mjs
const
files
=
process
.
argv
.
slice
(
3
)
;
const
ext
=
mode
===
"--cjs"
?
"cjs"
:
"mjs"
;
const
dtsExt
=
mode
===
"--cjs"
?
"d.cts"
:
"d.mts"
;
console
.
info
(
`Fixing
${
mode
}
files with extension
${
ext
}
`
)
;
for
(
const
file
of
files
)
{
if
(
file
.
endsWith
(
".d.ts"
)
)
{
// Handle declaration files: .d.ts => .d.mts or .d.cts
const
newFile
=
file
.
replace
(
/
\.
d
\.
t
s
$
/
,
`.
${
dtsExt
}
`
)
;
console
.
info
(
`Processing
${
file
}
=>
${
newFile
}
`
)
;
const
content
=
fs
.
readFileSync
(
file
)
.
toString
(
"utf-8"
)
;
// Fix import paths: .ts => .mjs or .cjs
const
newContent
=
content
.
replace
(
/
\b
f
r
o
m
"
(
\.
\.
?
\/
[
^
"
]
+
)
\.
t
s
"
;
/
g
,
`from "$1.
${
ext
}
";`
)
.
replace
(
/
\b
i
m
p
o
r
t
"
(
\.
\.
?
\/
[
^
"
]
+
)
\.
t
s
"
;
/
g
,
`import "$1.
${
ext
}
";`
)
;
fs
.
writeFileSync
(
newFile
,
newContent
)
;
fs
.
unlinkSync
(
file
)
;
}
else
if
(
file
.
endsWith
(
".js"
)
)
{
// Handle JS files: .js => .mjs or .cjs
const
fileMjs
=
file
.
replace
(
/
\.
j
s
$
/
,
`.
${
ext
}
`
)
;
console
.
info
(
`Processing
${
file
}
=>
${
fileMjs
}
`
)
;
const
content
=
fs
.
readFileSync
(
file
)
.
toString
(
"utf-8"
)
;
const
newContent
=
content
.
replace
(
/
\b
f
r
o
m
"
(
\.
\.
?
\/
[
^
"
]
+
)
\.
j
s
"
;
/
g
,
`from "$1.
${
ext
}
";`
)
.
replace
(
/
\b
i
m
p
o
r
t
"
(
\.
\.
?
\/
[
^
"
]
+
)
\.
j
s
"
;
/
g
,
`import "$1.
${
ext
}
";`
)
.
replace
(
/
\b
r
e
q
u
i
r
e
\(
"
(
\.
\.
?
\/
[
^
"
]
+
)
\.
j
s
"
\)
/
g
,
`require("$1.
${
ext
}
");`
)
.
replace
(
/
\/
\/
#
s
o
u
r
c
e
M
a
p
p
i
n
g
U
R
L
=
(
.
+
)
\.
j
s
\.
m
a
p
$
/
,
`//# sourceMappingURL=$1.
${
ext
}
.map`
)
;
fs
.
writeFileSync
(
fileMjs
,
newContent
)
;
fs
.
unlinkSync
(
file
)
;
// .js.map => .mjs.map
const
mapping
=
JSON
.
parse
(
fs
.
readFileSync
(
`
${
file
}
.map`
)
.
toString
(
"utf-8"
)
)
;
mapping
.
file
=
mapping
.
file
.
replace
(
/
\.
j
s
$
/
,
ext
)
;
fs
.
writeFileSync
(
`
${
fileMjs
}
.map`
,
JSON
.
stringify
(
mapping
)
)
;
fs
.
unlinkSync
(
`
${
file
}
.map`
)
;
}
}
Back
|
FazBrowse Home
|
New Git URL