-
Notifications
You must be signed in to change notification settings - Fork 4
remove node types and bun types from workflows #199
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
Changes from all commits
85c9cf4
a94277d
e62a01f
227700f
a776610
1e8ca6a
87fa5a8
afd1270
8352563
f55557d
d809ee7
8934ae7
504996a
c8a8218
28414a3
e742d67
ccc00e3
3a1136d
f4cf527
e775de4
d8acbcd
bd0a140
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.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /** | ||
| * This example shows how CRE workflows mark restricted APIs as deprecated in TS. | ||
| * | ||
| * The restricted APIs covered in this example are: | ||
| * - fetch | ||
| * - setTimeout | ||
| * - setInterval | ||
| * | ||
| * Other unsupported globals/modules are enforced by cre-compile runtime checks. | ||
| * There are also NodeJS APIs that do work with the QuickJS runtime, like console.log. | ||
| */ | ||
|
|
||
| export const testFetch = async () => { | ||
| // @ts-expect-error - fetch is not available in the CRE SDK | ||
| fetch('https://api.chain.link/v1/price?symbol=ETH/USD') | ||
| } | ||
|
|
||
| export const testSetTimeout = async () => { | ||
| // @ts-expect-error - setTimeout is not available in the CRE SDK | ||
| setTimeout(() => { | ||
| console.log('Hello, world!') | ||
| }, 1000) | ||
| } | ||
|
|
||
| export const testSetInterval = async () => { | ||
| // @ts-expect-error - setInterval is not available in the CRE SDK | ||
| setInterval(() => { | ||
| console.log('Hello, world!') | ||
| }, 1000) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| /** | ||
| * This example shows how CRE workflows mark restricted Node.js modules as `never` in TS. | ||
| * | ||
| * CRE workflows run on QuickJS (via Javy/WASM), not full Node.js. | ||
| * All exports from restricted modules are typed as `never`, so any usage | ||
| * produces a clear TypeScript error at the call site. | ||
| * | ||
| * The restricted modules covered in this example are: | ||
| * - node:crypto | ||
| * - node:fs | ||
| * - node:fs/promises | ||
| * - node:net | ||
| * - node:http | ||
| * - node:https | ||
| * - node:child_process | ||
| * - node:os | ||
| * - node:stream | ||
| * - node:worker_threads | ||
| * - node:dns | ||
| * - node:zlib | ||
| * | ||
| * For HTTP requests, use cre.capabilities.HTTPClient instead of node:http/node:https/node:net. | ||
| * | ||
| * @see https://docs.chain.link/cre/concepts/typescript-wasm-runtime | ||
| */ | ||
|
|
||
| import { exec } from 'node:child_process' | ||
| import { createHash, randomBytes } from 'node:crypto' | ||
| import { lookup } from 'node:dns' | ||
| import { readFileSync } from 'node:fs' | ||
| import { readFile } from 'node:fs/promises' | ||
| import { request as httpRequest } from 'node:http' | ||
| import { request as httpsRequest } from 'node:https' | ||
| import { createConnection } from 'node:net' | ||
| import { cpus, hostname } from 'node:os' | ||
| import { Readable } from 'node:stream' | ||
| import { Worker } from 'node:worker_threads' | ||
| import { createGzip } from 'node:zlib' | ||
|
|
||
| // --- node:crypto --- | ||
|
|
||
| export const testCryptoRandomBytes = () => { | ||
| // @ts-expect-error - node:crypto is not available in CRE WASM workflows | ||
| randomBytes(32) | ||
| } | ||
|
|
||
| export const testCryptoCreateHash = () => { | ||
| // @ts-expect-error - node:crypto is not available in CRE WASM workflows | ||
| createHash('sha256') | ||
| } | ||
|
|
||
| // --- node:fs --- | ||
|
|
||
| export const testFsReadFileSync = () => { | ||
| // @ts-expect-error - node:fs is not available in CRE WASM workflows | ||
| readFileSync('/etc/passwd', 'utf-8') | ||
| } | ||
|
|
||
| // --- node:fs/promises --- | ||
|
|
||
| export const testFsPromisesReadFile = async () => { | ||
| // @ts-expect-error - node:fs/promises is not available in CRE WASM workflows | ||
| await readFile('/etc/passwd', 'utf-8') | ||
| } | ||
|
|
||
| // --- node:net --- | ||
|
|
||
| export const testNetCreateConnection = () => { | ||
| // @ts-expect-error - node:net is not available in CRE WASM workflows | ||
| createConnection({ host: 'localhost', port: 8080 }) | ||
| } | ||
|
|
||
| // --- node:http --- | ||
|
|
||
| export const testHttpRequest = () => { | ||
| // @ts-expect-error - node:http is not available in CRE WASM workflows | ||
| httpRequest('http://example.com') | ||
| } | ||
|
|
||
| // --- node:https --- | ||
|
|
||
| export const testHttpsRequest = () => { | ||
| // @ts-expect-error - node:https is not available in CRE WASM workflows | ||
| httpsRequest('https://example.com') | ||
| } | ||
|
|
||
| // --- node:child_process --- | ||
|
|
||
| export const testChildProcessExec = () => { | ||
| // @ts-expect-error - node:child_process is not available in CRE WASM workflows | ||
| exec('ls -la') | ||
| } | ||
|
|
||
| // --- node:os --- | ||
|
|
||
| export const testOsHostname = () => { | ||
| // @ts-expect-error - node:os is not available in CRE WASM workflows | ||
| hostname() | ||
| } | ||
|
|
||
| export const testOsCpus = () => { | ||
| // @ts-expect-error - node:os is not available in CRE WASM workflows | ||
| cpus() | ||
| } | ||
|
|
||
| // --- node:stream --- | ||
|
|
||
| export const testStreamReadable = () => { | ||
| // @ts-expect-error - node:stream is not available in CRE WASM workflows | ||
| new Readable() | ||
| } | ||
|
|
||
| // --- node:worker_threads --- | ||
|
|
||
| export const testWorkerThreads = () => { | ||
| // @ts-expect-error - node:worker_threads is not available in CRE WASM workflows | ||
| new Worker('./worker.js') | ||
| } | ||
|
|
||
| // --- node:dns --- | ||
|
|
||
| export const testDnsLookup = () => { | ||
| // @ts-expect-error - node:dns is not available in CRE WASM workflows | ||
| lookup('example.com', () => {}) | ||
| } | ||
|
|
||
| // --- node:zlib --- | ||
|
|
||
| export const testZlibCreateGzip = () => { | ||
| // @ts-expect-error - node:zlib is not available in CRE WASM workflows | ||
| createGzip() | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,9 @@ | |
| "skipLibCheck": true, | ||
| "noFallthroughCasesInSwitch": true, | ||
|
|
||
| // Do not auto-include @types/* — mirrors the customer cre cli initialized environment | ||
| "types": [], | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to make sure the cre-cli tsconfigs match, or do they pull in this file directly now?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will follow up with CLI PR that initialize project with this settings. |
||
|
|
||
| // Some stricter flags (disabled by default) | ||
| "noUnusedLocals": false, | ||
| "noUnusedParameters": false, | ||
|
|
||
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.
Let's ensure we don't break existing workflows. TextDecoder still needs to work.
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 just "extra" cleanup in my example as using
textshall be more convenient for the users.TextDecoderdoes in fact still work and you can still use the previous notation if you prefer.