-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ew files for typescript project embeds.
- Loading branch information
Showing
20 changed files
with
218 additions
and
41 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,28 @@ | ||
load("@npm//:eslint/package_json.bzl", eslint_bin = "bin") | ||
|
||
def eslint_test(name, srcs, config, tsconfig, tags = []): | ||
"""Generates a test, which runs eslint. | ||
Args: | ||
name: target name | ||
srcs: source files to lint | ||
config: eslint config file | ||
tsconfig: tsconfig file | ||
""" | ||
eslint_bin.eslint_test( | ||
name = name, | ||
data = [ | ||
config, | ||
tsconfig, | ||
"//ts:eslintrc.base.json", | ||
"//ts:tsconfig.base.json", | ||
"//:node_modules/@typescript-eslint/eslint-plugin", | ||
] + srcs, | ||
args = [ | ||
"--config $(location " + config + ")", | ||
] + [ | ||
"$(location " + src + ")" | ||
for src in srcs | ||
], | ||
tags = ["lint"] + tags, | ||
) |
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,65 @@ | ||
load("@aspect_rules_ts//ts:defs.bzl", "ts_config", "ts_project") | ||
load("@workerd//:build/eslint_test.bzl", "eslint_test") | ||
load("@workerd//:build/wd_js_bundle.bzl", "wd_js_bundle") | ||
|
||
def _js_modules(ts_modules): | ||
"""convert dict with ts modules to dict with js modules.""" | ||
return dict([ | ||
(f.removesuffix(".ts") + ".js", m) | ||
for f, m in ts_modules.items() | ||
# .d.ts do not generate .js | ||
if not f.endswith(".d.ts")]) | ||
|
||
|
||
def wd_ts_project_embed( | ||
name, | ||
builtin_modules, | ||
internal_modules, | ||
tsconfig, | ||
eslintrc, | ||
tags = []): | ||
"""Define typescript project embedding compiled code into c++ library. | ||
Args: | ||
name: project name | ||
srcs: .ts source files | ||
tsconfig: tsconfig.json file for the project | ||
""" | ||
|
||
srcs = list(builtin_modules) + list(internal_modules) | ||
|
||
ts_config( | ||
name = name + "@tsconfig", | ||
src = tsconfig, | ||
deps = ["//ts:tsconfig.base.json"], | ||
tags = tags, | ||
) | ||
|
||
ts_project( | ||
name = name, | ||
srcs = srcs, | ||
tsconfig = ":{}@tsconfig".format(name), | ||
deps = ["//:node_modules/@cloudflare/workers-types"], | ||
tags = tags, | ||
) | ||
|
||
wd_js_bundle( | ||
name = name + "_bundle", | ||
schema_id = "0xb7723ddc413262ab", | ||
const_name = name + "Bundle", | ||
builtin_modules = _js_modules(builtin_modules), | ||
internal_modules = _js_modules(internal_modules), | ||
tags = tags, | ||
target_compatible_with = select({ | ||
"@//build/config:no_build": ["@platforms//:incompatible"], | ||
"//conditions:default": [], | ||
}), | ||
) | ||
|
||
eslint_test( | ||
name = name + "@eslint", | ||
srcs = srcs, | ||
config = eslintrc, | ||
tsconfig = tsconfig, | ||
tags = tags, | ||
) |
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 was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
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,44 @@ | ||
load("@workerd//:build/wd_ts_project_embed.bzl", "wd_ts_project_embed") | ||
|
||
# these will be accessible under "node:<name_without_extension>" | ||
node_modules = glob(["node/*.ts"]) | ||
|
||
# these will be accessible under "node-internal:<name_without_extension>" | ||
node_internal_modules = glob(["node/internal/*.ts"]) | ||
|
||
# these will be accessible under "cloudflare:<name_without_extension>" | ||
cloudflare_modules = glob(["cloudflare/*.ts"]) | ||
|
||
# these will be accessible under "cloudflare-internal:<name_without_extension>" | ||
cloudflare_internal_modules = glob(["cloudflare/internal/*.ts"]) | ||
|
||
wd_ts_project_embed( | ||
# give bundle an "internal" name to be clear which one comes from workerd/edgeworker. | ||
name = "nodeEdgeworker", | ||
builtin_modules = dict([( | ||
m, | ||
"node:" + m.removeprefix("node/").removesuffix(".ts"), | ||
) for m in node_modules]), | ||
eslintrc = "node/.eslintrc.json", | ||
internal_modules = dict([( | ||
m, | ||
"node-internal:" + m.removeprefix("node/internal/").removesuffix(".ts"), | ||
) for m in node_internal_modules]), | ||
tags = ["no-arm64"], | ||
tsconfig = "node/tsconfig.json", | ||
) | ||
|
||
wd_ts_project_embed( | ||
name = "cloudflareEdgeworker", | ||
builtin_modules = dict([( | ||
m, | ||
"cloudflare:" + m.removeprefix("cloudflare/").removesuffix(".ts"), | ||
) for m in cloudflare_modules]), | ||
eslintrc = "cloudflare/.eslintrc.json", | ||
internal_modules = dict([( | ||
m, | ||
"cloudflare-internal:" + m.removeprefix("cloudflare/internal/").removesuffix(".ts"), | ||
) for m in cloudflare_internal_modules]), | ||
tags = ["no-arm64"], | ||
tsconfig = "cloudflare/tsconfig.json", | ||
) |
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,6 @@ | ||
{ | ||
"extends": "../eslintrc.base.json", | ||
"parserOptions": { | ||
"project": "ts/cloudflare/tsconfig.json" | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,14 @@ | ||
{ | ||
"extends": "../tsconfig.base.json", | ||
"compilerOptions": { | ||
"types": ["@cloudflare/workers-types"], | ||
"paths": { | ||
"cloudflare:*": ["./*"], | ||
"cloudflare-internal:*": ["./internal/*"], | ||
} | ||
}, | ||
"include": [ | ||
"*.ts", | ||
"internal/*.ts" | ||
], | ||
} |
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,24 @@ | ||
{ | ||
"env": { | ||
"es2022": true, | ||
"worker": true | ||
}, | ||
"extends": [ | ||
"plugin:@typescript-eslint/recommended", | ||
"plugin:@typescript-eslint/recommended-requiring-type-checking", | ||
"plugin:@typescript-eslint/strict" | ||
], | ||
"overrides": [], | ||
"parserOptions": { | ||
"ecmaVersion": "latest", | ||
"sourceType": "module" | ||
}, | ||
"rules": { | ||
"@typescript-eslint/explicit-function-return-type": "error", | ||
"@typescript-eslint/explicit-member-accessibility": "error", | ||
"@typescript-eslint/explicit-module-boundary-types": "error", | ||
"@typescript-eslint/no-require-imports": "error", | ||
"@typescript-eslint/prefer-enum-initializers": "error", | ||
"@typescript-eslint/type-annotation-spacing": "error" | ||
} | ||
} |
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,6 @@ | ||
{ | ||
"extends": "../eslintrc.base.json", | ||
"parserOptions": { | ||
"project": "ts/node/tsconfig.json" | ||
} | ||
} |
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,8 @@ | ||
export function basename(path: string, ext?: string): string { | ||
if (ext) { | ||
throw new Error(`basename with ext not implemented: ${path} ${ext}`); | ||
} | ||
|
||
const idx = path.lastIndexOf("/"); | ||
return idx >= 0 ? path.substring(idx + 1) : path; | ||
} |
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,14 @@ | ||
{ | ||
"extends": "../tsconfig.base.json", | ||
"compilerOptions": { | ||
"types": ["@cloudflare/workers-types"], | ||
"paths": { | ||
"node:*": ["./*"], | ||
"node-internal:*": ["./internal/*"], | ||
} | ||
}, | ||
"include": [ | ||
"*.ts", | ||
"internal/*.ts" | ||
], | ||
} |
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