-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore!: publish gax-nodejs in dual format (CJS and ESM) #1679
base: main
Are you sure you want to change the base?
Changes from 21 commits
d65013f
287271b
24b6195
3566f28
955896c
237abba
8e57aea
a17f484
e702960
57acad4
53d9f3f
882a1d9
1a66338
1656a87
7f68430
200d304
9a34cbd
d27baf9
c8d0d22
10837c3
28ae15b
82f62bd
82ed56e
520e4d8
32fd81e
2a0dd66
0f0c1b6
be673ee
c298e08
1aede4a
4c93886
f1be309
ed5055a
5c212dc
97ab9b9
901b20f
fd44396
7df63e0
a98c2d5
6f306ec
14ca692
98d9366
76f5565
048e05b
ccf8a34
896679f
f4926a7
2d5e67f
2a2bce1
00e2472
f07c571
a1b539e
fdb98ae
f78fcd9
dc5c20d
7d4f877
8ebae3c
7c9dbe7
a8bca8a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
This file was deleted.
This file was deleted.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"presets": [ | ||
"@babel/preset-typescript", | ||
"@babel/env" | ||
], | ||
"plugins": [ | ||
[ | ||
"replace-import-extension", | ||
{ | ||
"extMapping": { | ||
".js": ".cjs" | ||
} | ||
} | ||
], | ||
"./node_modules/gapic-tools/build/src/replaceESMMockingLib.js", | ||
"./node_modules/gapic-tools/build/src/replaceImportMetaUrl.js", | ||
"./node_modules/gapic-tools/build/src/toggleESMFlagVariable.js" | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,3 +23,6 @@ dist/ | |
*.tgz | ||
**/*.tgz | ||
test/showcase-echo-client/protos/protos.* | ||
**/*.d.ts | ||
*.d.ts | ||
**/**.d.ts |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
function getAllFiles(dirPath, arrayOfFiles) { | ||
const files = fs.readdirSync(dirPath); | ||
|
||
arrayOfFiles = arrayOfFiles || []; | ||
|
||
files.forEach(file => { | ||
if (fs.statSync(path.join(dirPath, file)).isDirectory()) { | ||
arrayOfFiles = getAllFiles(path.join(dirPath, file), arrayOfFiles); | ||
} else { | ||
arrayOfFiles.push(path.join(dirPath, file)); | ||
} | ||
}); | ||
|
||
return arrayOfFiles; | ||
} | ||
|
||
function getAllFullFilePaths(dirname, filenames) { | ||
// const files = fs.readdirSync(dirPath); | ||
|
||
const arrayOfFiles = []; | ||
|
||
filenames.forEach(file => { | ||
arrayOfFiles.push(path.join(dirname, file)); | ||
}); | ||
|
||
return arrayOfFiles; | ||
} | ||
|
||
function main(directoryOrFilenames) { | ||
let fileNames; | ||
if ( | ||
fs.statSync(path.join(__dirname, directoryOrFilenames[0])).isDirectory() | ||
) { | ||
fileNames = getAllFiles(directoryOrFilenames[0]); | ||
} else { | ||
fileNames = getAllFullFilePaths(__dirname, directoryOrFilenames); | ||
} | ||
for (const file of fileNames) { | ||
let contents = fs.readFileSync(file, 'utf8'); | ||
if (contents.includes('proxyquire')) { | ||
contents = contents.replace(/\.js'/g, ".cjs'"); | ||
fs.writeFileSync(file, contents); | ||
} | ||
} | ||
} | ||
|
||
main(process.argv.slice(2)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not add a package.json with
type: commonjs
? According to spec:Additionally reading/examples for this pattern:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is for changing the extension in proxyquire calls, so it wouldn't be affected by a package.json, although I see your larger point that we wouldn't even have to do that if we didn't rename the files at all. It seems slightly cleaner/safer to me to have the .cjs and .js distinguishing the files, easier to see at a glance what's going on, but that's just my perspective!