mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 07:14:47 -05:00
Remove msg_generated hack (#409)
This commit is contained in:
parent
180170d860
commit
5562c36824
9 changed files with 47 additions and 1877 deletions
|
@ -1,2 +1 @@
|
|||
js/msg_generated.ts
|
||||
js/flatbuffers.js
|
||||
|
|
32
BUILD.gn
32
BUILD.gn
|
@ -194,11 +194,11 @@ run_node("bundle") {
|
|||
"js/dispatch.ts",
|
||||
"js/globals.ts",
|
||||
"js/main.ts",
|
||||
"js/msg_generated.ts",
|
||||
"js/os.ts",
|
||||
"js/runtime.ts",
|
||||
"js/types.ts",
|
||||
"js/util.ts",
|
||||
"src/msg.fbs",
|
||||
"rollup.config.js",
|
||||
"tsconfig.json",
|
||||
]
|
||||
|
@ -207,7 +207,7 @@ run_node("bundle") {
|
|||
out_dir + "main.js.map",
|
||||
]
|
||||
deps = [
|
||||
":flatbufferjs",
|
||||
":msg_ts",
|
||||
]
|
||||
args = [
|
||||
"./node_modules/rollup/bin/rollup",
|
||||
|
@ -237,34 +237,6 @@ source_set("libdeno_nosnapshot") {
|
|||
defines = [ "BUNDLE_LOCATION=\"$bundle_location\"" ]
|
||||
}
|
||||
|
||||
# Generates flatbuffer TypeScript code.
|
||||
# TODO(ry) Ideally flatc output files should be written into
|
||||
# target_gen_dir, but its difficult to get this working in a way that the
|
||||
# bundler can resolve their location. (The bundler does not support NODE_PATH?)
|
||||
# Therefore this hack: write the msg_generated.ts output
|
||||
# into the js/ folder, and we check it into the repo. Hopefully this hack can
|
||||
# be removed at some point. If msg.fps is changed, commit changes to the
|
||||
# generated JS files. The stamp file is just to make gn work.
|
||||
action("flatbufferjs") {
|
||||
script = "//tools/flatbufferjs_hack.py"
|
||||
sources = [
|
||||
"src/msg.fbs",
|
||||
]
|
||||
outputs = [
|
||||
"$target_gen_dir/flatbufferjs_hack.stamp",
|
||||
]
|
||||
|
||||
args = [
|
||||
rebase_path("$target_gen_dir/msg_generated.ts", root_build_dir),
|
||||
rebase_path("js/msg_generated.ts", root_build_dir),
|
||||
rebase_path(outputs[0], root_build_dir),
|
||||
]
|
||||
|
||||
deps = [
|
||||
":msg_ts",
|
||||
]
|
||||
}
|
||||
|
||||
ts_flatbuffer("msg_ts") {
|
||||
sources = [
|
||||
"src/msg.fbs",
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// tslint:disable-next-line:no-reference
|
||||
/// <reference path="deno.d.ts" />
|
||||
import { flatbuffers } from "flatbuffers";
|
||||
import { deno as fbs } from "./msg_generated";
|
||||
import { deno as fbs } from "gen/msg_generated";
|
||||
import { assert, log } from "./util";
|
||||
import * as runtime from "./runtime";
|
||||
|
||||
|
|
1812
js/msg_generated.ts
1812
js/msg_generated.ts
File diff suppressed because it is too large
Load diff
2
js/os.ts
2
js/os.ts
|
@ -1,6 +1,6 @@
|
|||
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
|
||||
import { ModuleInfo } from "./types";
|
||||
import { deno as fbs } from "./msg_generated";
|
||||
import { deno as fbs } from "gen/msg_generated";
|
||||
import { assert } from "./util";
|
||||
import * as util from "./util";
|
||||
import { flatbuffers } from "flatbuffers";
|
||||
|
|
|
@ -13,6 +13,16 @@ const typescriptPath = `${
|
|||
process.env.BASEPATH
|
||||
}/third_party/node_modules/typescript/lib/typescript.js`;
|
||||
|
||||
// We will allow generated modules to be resolvable by TypeScript based on
|
||||
// the current build path
|
||||
const tsconfigOverride = {
|
||||
compilerOptions: {
|
||||
paths: {
|
||||
"*": ["*", path.join(process.cwd(), "*")]
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// this is a rollup plugin which will look for imports ending with `!string` and resolve
|
||||
// them with a module that will inline the contents of the file as a string. Needed to
|
||||
// support `js/assets.ts`.
|
||||
|
@ -48,6 +58,23 @@ function strings({ include, exclude } = {}) {
|
|||
};
|
||||
}
|
||||
|
||||
// This plugin resolves at bundle time any generated resources that are
|
||||
// in the build path under `gen` and specified with a MID starting with `gen/`.
|
||||
// The plugin assumes that the MID needs to have the `.ts` extension appended.
|
||||
function resolveGenerated() {
|
||||
return {
|
||||
name: "resolve-msg-generated",
|
||||
resolveId(importee) {
|
||||
if (importee.startsWith("gen/")) {
|
||||
const resolved = path.resolve(
|
||||
path.join(process.cwd(), `${importee}.ts`)
|
||||
);
|
||||
return resolved;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export default function makeConfig(commandOptions) {
|
||||
return {
|
||||
output: {
|
||||
|
@ -70,6 +97,9 @@ export default function makeConfig(commandOptions) {
|
|||
module: mockPath
|
||||
}),
|
||||
|
||||
// Resolves any resources that have been generated at build time
|
||||
resolveGenerated(),
|
||||
|
||||
// Allows rollup to resolve modules based on Node.js resolution
|
||||
nodeResolve({
|
||||
jsnext: true,
|
||||
|
@ -93,15 +123,18 @@ export default function makeConfig(commandOptions) {
|
|||
}),
|
||||
|
||||
typescript({
|
||||
// The build script is invoked from `out/Target` and so config is located alongside this file
|
||||
// The build script is invoked from `out/:target` so passing an absolute file path is needed
|
||||
tsconfig,
|
||||
|
||||
// This provides any overrides to the `tsconfig.json` that are needed to bundle
|
||||
tsconfigOverride,
|
||||
|
||||
// By default, the include path only includes the cwd and below, need to include the root of the project
|
||||
// to be passed to this plugin. This is different front tsconfig.json include
|
||||
include: ["*.ts", `${__dirname}/**/*.ts`],
|
||||
// and build path to be passed to this plugin. This is different front tsconfig.json include
|
||||
include: ["*.ts", `${__dirname}/**/*.ts`, `${process.cwd()}/**/*.ts`],
|
||||
|
||||
// d.ts files are not bundled and by default like include, it only includes the cwd and below
|
||||
exclude: ["*.d.ts", `${__dirname}/**/*.d.ts`]
|
||||
exclude: ["*.d.ts", `${__dirname}/**/*.d.ts`, `${process.cwd()}/**/*.d.ts`]
|
||||
}),
|
||||
|
||||
// Provides inlining of file contents for `js/assets.ts`
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
"""
|
||||
gn can only run python scripts.
|
||||
|
||||
Generates flatbuffer TypeScript code.
|
||||
"""
|
||||
import subprocess
|
||||
import sys
|
||||
import os
|
||||
import shutil
|
||||
import util
|
||||
|
||||
# TODO(ry) Ideally flatc output files should be written into target_gen_dir, but
|
||||
# its difficult to get this working in a way that parcel can resolve their
|
||||
# location. (Parcel does not support NODE_PATH.) Therefore this hack: write the
|
||||
# generated msg_generated.ts outputs into the js/ folder, and we check them into
|
||||
# the repo. Hopefully this hack can be removed at some point. If msg.fps is
|
||||
# changed, commit changes to the generated JS file.
|
||||
|
||||
src = sys.argv[1]
|
||||
dst = sys.argv[2]
|
||||
stamp_file = sys.argv[3]
|
||||
|
||||
shutil.copyfile(src, dst)
|
||||
|
||||
util.touch(stamp_file)
|
|
@ -23,7 +23,7 @@ run(["yapf", "-i"] + find_exts("tools/", ".py") +
|
|||
find_exts("build_extra", ".py"))
|
||||
|
||||
run(["node", prettier, "--write"] + find_exts("js/", ".js", ".ts") +
|
||||
["tsconfig.json", "tslint.json"])
|
||||
["rollup.config.js", "tsconfig.json", "tslint.json"])
|
||||
|
||||
# Set RUSTFMT_FLAGS for extra flags.
|
||||
rustfmt_extra_args = []
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"allowJs": true,
|
||||
"baseUrl": ".",
|
||||
"module": "esnext",
|
||||
"noImplicitAny": true,
|
||||
"sourceMap": true,
|
||||
|
@ -12,7 +13,10 @@
|
|||
"pretty": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"allowUnreachableCode": false,
|
||||
"experimentalDecorators": true
|
||||
"experimentalDecorators": true,
|
||||
"paths": {
|
||||
"*": [ "*", "out/debug/*", "out/default/*", "out/release/*" ]
|
||||
}
|
||||
},
|
||||
"include": ["js/main.ts"],
|
||||
"exclude": ["node_modules"]
|
||||
|
|
Loading…
Reference in a new issue