-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from hopinc/feat/https-on-node-only
- Loading branch information
Showing
7 changed files
with
41 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@onehop/js': minor | ||
--- | ||
|
||
Make await import('https') only run on node using conditional export |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Variables defined in tsup.config.ts | ||
// Used to build specific code for specific runtimes | ||
// while doing deadcode elimination | ||
|
||
declare const TSUP_IS_NODE: boolean; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,35 @@ | ||
import {defineConfig} from 'tsup'; | ||
import {defineConfig, type Options} from 'tsup'; | ||
|
||
import glob from 'glob'; | ||
import fs from 'fs'; | ||
|
||
const utils = glob.sync('./src/utils/*'); | ||
|
||
/** | ||
* Generate a package.json file for a util | ||
* | ||
* @param {string} utilName The name of the util to be exported | ||
* @returns A package.json config | ||
*/ | ||
function pkg(utilName: string) { | ||
return JSON.stringify( | ||
{ | ||
main: `../../dist/utils/${utilName}/index.js`, | ||
module: `../../dist/utils/${utilName}/index.mjs`, | ||
types: `../../dist/utils/${utilName}/index.d.ts`, | ||
}, | ||
null, | ||
4, | ||
); | ||
} | ||
|
||
export default defineConfig({ | ||
entry: ['src/index.ts', 'src/utils/*/index.ts'], | ||
const commonBuild: Options = { | ||
splitting: true, | ||
clean: true, | ||
minify: false, | ||
sourcemap: true, | ||
dts: true, | ||
format: ['cjs', 'esm'], | ||
minifySyntax: true, | ||
minifyWhitespace: true, | ||
target: 'esnext', | ||
define: { | ||
TSUP_DEBUG: 'false', | ||
banner: { | ||
js: `/* Copyright ${new Date().getFullYear()} Hop, Inc */`, | ||
}, | ||
onSuccess: async () => { | ||
if (!fs.existsSync('./utils')) { | ||
fs.mkdirSync('./utils'); | ||
} | ||
|
||
for (const util of utils) { | ||
const utilName = util.split('/').pop(); | ||
}; | ||
|
||
if (!utilName) { | ||
continue; | ||
} | ||
|
||
const directory = `./utils/${utilName}`; | ||
|
||
if (!fs.existsSync(directory)) { | ||
fs.mkdirSync(directory); | ||
} | ||
const define = ({node = false} = {}) => ({ | ||
TSUP_IS_NODE: JSON.stringify(node), | ||
}); | ||
|
||
fs.writeFileSync(`${directory}/package.json`, pkg(utilName), 'utf-8'); | ||
} | ||
export default defineConfig([ | ||
{ | ||
...commonBuild, | ||
entry: ['src/index.ts', 'src/utils/*/index.ts'], | ||
define: define(), | ||
}, | ||
banner: { | ||
js: `/* Copyright ${new Date().getFullYear()} Hop, Inc */`, | ||
{ | ||
...commonBuild, | ||
entry: ['src/index.ts'], | ||
outDir: 'dist/node', | ||
define: define({ | ||
node: true, | ||
}), | ||
}, | ||
}); | ||
]); |
a7f7363
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.
Successfully deployed to the following URLs:
hop-js – ./
hop-js.vercel.app
hop-js-onehop.vercel.app
hop-js-git-master-onehop.vercel.app
js.hop.io