chore: support typescript packages

This commit is contained in:
Michael Rawlings 2023-07-21 15:35:15 -04:00
parent bce8f4b11c
commit 2b17b66f51
17 changed files with 3402 additions and 9816 deletions

View File

@ -1,5 +1,15 @@
{ {
"all": true, "all": true,
"include": ["packages/*/src/**/*.js"], "parserPlugins": ["objectRestSpread", "typescript"],
"reporter": ["lcov", "text-summary"] "reporter": ["text-summary", "lcov"],
"include": [
"packages/*/src/**/*.js",
"packages/*/src/**/*.ts",
"packages/*/src/**/*.marko"
],
"exclude": [
"**/__tests__",
"packages/runtime/src/html/reorder-runtime.ts",
"**/*.d.ts"
]
} }

View File

@ -11,3 +11,5 @@ coverage/
*generated/ *generated/
~vdom.skip ~vdom.skip
**/test/**/input.js **/test/**/input.js
.vscode
__snapshots__

View File

@ -25,5 +25,26 @@
"ignoreDeclarationSort": true "ignoreDeclarationSort": true
} }
] ]
} },
"overrides": [
{
"files": ["**/*.ts"],
"parser": "@typescript-eslint/parser",
"extends": [
"eslint:recommended",
"plugin:import/typescript",
"plugin:@typescript-eslint/recommended",
"prettier"
],
"rules": {
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-empty-interface": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-namespace": "off"
}
}
]
} }

1
.gitattributes vendored Normal file
View File

@ -0,0 +1 @@
package-lock.json -diff

9
.gitignore vendored
View File

@ -1,8 +1,8 @@
### Project ### # Build
*.marko.js
*actual.*
dist dist
*.marko.js
*actual*
*.tsbuildinfo
### Node ### ### Node ###
@ -93,6 +93,7 @@ Icon
# VisualStudioCode # VisualStudioCode
.vscode .vscode
.history .history
*.sublime*
# JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm # JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
*.iml *.iml

8
.lintstagedrc.json Normal file
View File

@ -0,0 +1,8 @@
{
"*.ts": ["eslint --fix", "prettier --write"],
"*{.js,.json,.md,.yml,rc}": ["prettier --write"],
"./{,packages/*/}package.json": [
"prettier --write",
"sort-package-json --quiet"
]
}

View File

@ -1,6 +1,7 @@
{ {
"timeout": 5000,
"enable-source-maps": true, "enable-source-maps": true,
"spec": "packages/**/@(test|__tests__)/**/*.test.@(js|ts)", "require": ["~ts", "mocha-snap"],
"watchFiles": ["packages/*/src/**/*.@(js|ts|marko)", "!**/__snapshots__/**"], "spec": ["packages/*/@(src|test)/**/*.test.@(js|ts)"],
"require": ["@babel/register"] "watchFiles": ["src/**/*.@(js|ts|marko)", "!**/__snapshots__/**"]
} }

View File

@ -25,4 +25,7 @@ package.json
# controlled by lerna # controlled by lerna
CHANGELOG.md CHANGELOG.md
lerna.json lerna.json
# editor
.vscode

10
.prettierrc.json Normal file
View File

@ -0,0 +1,10 @@
{
"overrides": [
{
"files": "*rc",
"options": {
"parser": "json"
}
}
]
}

13049
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -5,8 +5,8 @@
"./packages/*" "./packages/*"
], ],
"scripts": { "scripts": {
"build": "npm run build --ws", "build": "npm run build --ws && npm run build:types",
"build:types": "npm run build:types --ws --if-present", "build:types": "npm run build:types --ws --if-present && tsc -b tsconfig.build.json",
"change": "changeset add", "change": "changeset add",
"ci:report": "c8 report --reporter=text-lcov > coverage.lcov && codecov", "ci:report": "c8 report --reporter=text-lcov > coverage.lcov && codecov",
"ci:test": "cross-env NODE_OPTIONS=\"--max-old-space-size=4096\" MARKO_DEBUG=1 c8 npm test", "ci:test": "cross-env NODE_OPTIONS=\"--max-old-space-size=4096\" MARKO_DEBUG=1 c8 npm test",
@ -19,20 +19,30 @@
"report": "open ./coverage/lcov-report/index.html", "report": "open ./coverage/lcov-report/index.html",
"set-entry": "npm exec --ws -c 'dot-json package.json main $(dot-json package.json $ENTRY)'", "set-entry": "npm exec --ws -c 'dot-json package.json main $(dot-json package.json $ENTRY)'",
"test": "mocha", "test": "mocha",
"test:watch": "npm run mocha -- --recursive --watch", "test:update": "UPDATE_EXPECTATIONS=1 mocha --update",
"version": "changeset version && npm i --package-lock-only" "version": "changeset version && npm i --package-lock-only"
}, },
"devDependencies": { "devDependencies": {
"@babel/cli": "^7.16.0", "@babel/cli": "^7.16.0",
"@babel/core": "^7.16.0", "@babel/core": "^7.16.0",
"@babel/plugin-transform-export-namespace-from": "^7.22.5",
"@babel/plugin-transform-modules-commonjs": "^7.22.5",
"@babel/plugin-transform-runtime": "^7.16.0", "@babel/plugin-transform-runtime": "^7.16.0",
"@babel/preset-env": "^7.16.0", "@babel/preset-env": "^7.16.0",
"@babel/preset-typescript": "^7.22.5",
"@babel/register": "^7.16.0", "@babel/register": "^7.16.0",
"@changesets/changelog-github": "^0.4.8", "@changesets/changelog-github": "^0.4.8",
"@changesets/cli": "^2.26.0", "@changesets/cli": "^2.26.0",
"@ebay/browserslist-config": "^1.2.0", "@ebay/browserslist-config": "^1.2.0",
"@rollup/plugin-terser": "^0.4.3",
"@rollup/plugin-virtual": "^3.0.1",
"@types/babel__code-frame": "^7.0.3",
"@types/babel__traverse": "^7.14.2", "@types/babel__traverse": "^7.14.2",
"babel-plugin-istanbul": "^6.1.1", "@types/jsdom": "^21.1.1",
"@types/mocha": "^10.0.1",
"@types/node": "^20.3.1",
"@typescript-eslint/eslint-plugin": "^5.59.11",
"@typescript-eslint/parser": "^5.59.11",
"babel-plugin-minprops": "^2.0.1", "babel-plugin-minprops": "^2.0.1",
"bluebird": "^3.7.2", "bluebird": "^3.7.2",
"c8": "^8.0.0", "c8": "^8.0.0",
@ -40,20 +50,30 @@
"cross-env": "^7.0.3", "cross-env": "^7.0.3",
"diffable-html": "^4.0.0", "diffable-html": "^4.0.0",
"dot-json": "^1.2.2", "dot-json": "^1.2.2",
"esbuild": "^0.18.2",
"eslint": "^7.22.0", "eslint": "^7.22.0",
"eslint-config-prettier": "^8.1.0", "eslint-config-prettier": "^8.1.0",
"eslint-import-resolver-typescript": "^3.5.5",
"express": "^4.17.1", "express": "^4.17.1",
"husky": "^8.0.0", "husky": "^8.0.0",
"it-fails": "^1.0.5", "it-fails": "^1.0.5",
"jsdom": "^19.0.0", "jsdom": "^19.0.0",
"jsdom-context-require": "^4.0.4", "jsdom-context-require": "^4.0.4",
"kleur": "^4.1.5",
"lint-staged": "^10.5.4", "lint-staged": "^10.5.4",
"mocha": "^8.3.2", "mocha": "^8.3.2",
"mocha-autotest": "^1.1.0", "mocha-autotest": "^1.1.0",
"mocha-snap": "^5.0.0",
"prettier": "^2.8.8", "prettier": "^2.8.8",
"pretty-format": "^29.5.0",
"rollup": "^3.25.1",
"shell-quote": "^1.7.2", "shell-quote": "^1.7.2",
"sort-package-json": "^2.4.1", "sort-package-json": "^2.4.1",
"table": "^6.8.1",
"through": "^2.3.8", "through": "^2.3.8",
"through2": "^4.0.2" "through2": "^4.0.2",
"tiny-glob": "^0.2.9",
"typescript": "^5.1.3",
"~ts": "file:scripts/babel-register.js"
} }
} }

View File

@ -1,5 +1,5 @@
import { SourceMap } from "magic-string"; import { SourceMap } from "magic-string";
import { TaglibLookup, Diagnostic } from "@marko/babel-utils"; import { Diagnostic, TaglibLookup } from "@marko/babel-utils";
import * as types from "./babel-types"; import * as types from "./babel-types";
export { types }; export { types };

View File

@ -216,6 +216,7 @@ declare global {
} }
/** The top level api for a Marko Template. */ /** The top level api for a Marko Template. */
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export abstract class Template<Input = unknown, Return = unknown> { export abstract class Template<Input = unknown, Return = unknown> {
/** Creates a Marko compatible output stream. */ /** Creates a Marko compatible output stream. */
createOut(): Out; createOut(): Out;

View File

@ -186,6 +186,7 @@ declare global {
| "prev" | "prev"
| "search" | "search"
| "tag" | "tag"
// eslint-disable-next-line @typescript-eslint/ban-types
| (string & {}); | (string & {});
/** /**
@ -313,6 +314,7 @@ declare global {
| "nofullscreen" | "nofullscreen"
| "noplaybackrate" | "noplaybackrate"
| "noremoteplayback" | "noremoteplayback"
// eslint-disable-next-line @typescript-eslint/ban-types
| (string & {}); | (string & {});
/** /**
@ -816,6 +818,7 @@ declare global {
| "opener" | "opener"
| "prev" | "prev"
| "search" | "search"
// eslint-disable-next-line @typescript-eslint/ban-types
| (string & {}); | (string & {});
/** /**
* Specifies the browsing context in which the linked resource will be opened. * Specifies the browsing context in which the linked resource will be opened.
@ -925,6 +928,7 @@ declare global {
| "allow-top-navigation-by-user-activation" | "allow-top-navigation-by-user-activation"
| "allow-top-navigation-to-custom-protocols" | "allow-top-navigation-to-custom-protocols"
| "allow-top-navigation" | "allow-top-navigation"
// eslint-disable-next-line @typescript-eslint/ban-types
| (string & {}); | (string & {});
/** /**
* The URL of the page to embed in the iframe. * The URL of the page to embed in the iframe.
@ -1429,6 +1433,7 @@ declare global {
| "prev" | "prev"
| "search" | "search"
| "stylesheet" | "stylesheet"
// eslint-disable-next-line @typescript-eslint/ban-types
| (string & {}); | (string & {});
/** /**
@ -1779,6 +1784,7 @@ declare global {
| "application/javascript" | "application/javascript"
| "module" | "module"
| "import-map" | "import-map"
// eslint-disable-next-line @typescript-eslint/ban-types
| (string & {}); | (string & {});
/** @deprecated */ /** @deprecated */
@ -2236,6 +2242,7 @@ declare global {
| "nofullscreen" | "nofullscreen"
| "noplaybackrate" | "noplaybackrate"
| "noremoteplayback" | "noremoteplayback"
// eslint-disable-next-line @typescript-eslint/ban-types
| (string & {}); | (string & {});
/** /**
@ -3913,6 +3920,7 @@ type AttrTarget =
| "_parent" | "_parent"
| "_self" | "_self"
| "_top" | "_top"
// eslint-disable-next-line @typescript-eslint/ban-types
| (string & {}); | (string & {});
type AttrReferrerPolicy = type AttrReferrerPolicy =
| AttrMissing | AttrMissing
@ -3985,6 +3993,7 @@ type AttrAutoComplete =
| "mobile" | "mobile"
| "fax" | "fax"
| "pager" | "pager"
// eslint-disable-next-line @typescript-eslint/ban-types
| (string & {}); | (string & {});
type Tag<Input> = Input extends Marko.HTMLAttributes<infer Element> type Tag<Input> = Input extends Marko.HTMLAttributes<infer Element>
? Marko.NativeTag<Input, Element> ? Marko.NativeTag<Input, Element>

11
scripts/babel-register.js Normal file
View File

@ -0,0 +1,11 @@
// aliased as ~ts via package.json
require("@babel/register")({
babelrc: false,
configFile: false,
extensions: [".js", ".ts"],
presets: ["@babel/preset-typescript"],
plugins: [
"@babel/plugin-transform-modules-commonjs",
"@babel/plugin-transform-export-namespace-from",
],
});

8
tsconfig.build.json Normal file
View File

@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"exclude": ["**/dist"],
"compilerOptions": {
"noEmit": true,
"emitDeclarationOnly": false
}
}

29
tsconfig.json Normal file
View File

@ -0,0 +1,29 @@
{
"compilerOptions": {
"lib": ["dom", "ESNext"],
"strict": true,
"outDir": "dist",
"composite": true,
"target": "ESNext",
"sourceMap": false,
"declaration": true,
"incremental": true,
"module": "ESNext",
"skipLibCheck": true,
"stripInternal": true,
"noUnusedLocals": true,
"isolatedModules": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"noUnusedParameters": true,
"allowUnusedLabels": false,
"noImplicitReturns": false,
"noImplicitOverride": true,
"emitDeclarationOnly": true,
"verbatimModuleSyntax": true,
"moduleResolution": "bundler",
"allowUnreachableCode": false,
"allowImportingTsExtensions": true,
"forceConsistentCasingInFileNames": true
}
}