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,
"include": ["packages/*/src/**/*.js"],
"reporter": ["lcov", "text-summary"]
"parserPlugins": ["objectRestSpread", "typescript"],
"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/
~vdom.skip
**/test/**/input.js
.vscode
__snapshots__

View File

@ -25,5 +25,26 @@
"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 ###
*.marko.js
*actual.*
# Build
dist
*.marko.js
*actual*
*.tsbuildinfo
### Node ###
@ -93,6 +93,7 @@ Icon
# VisualStudioCode
.vscode
.history
*.sublime*
# JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
*.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,
"spec": "packages/**/@(test|__tests__)/**/*.test.@(js|ts)",
"watchFiles": ["packages/*/src/**/*.@(js|ts|marko)", "!**/__snapshots__/**"],
"require": ["@babel/register"]
"require": ["~ts", "mocha-snap"],
"spec": ["packages/*/@(src|test)/**/*.test.@(js|ts)"],
"watchFiles": ["src/**/*.@(js|ts|marko)", "!**/__snapshots__/**"]
}

View File

@ -25,4 +25,7 @@ package.json
# controlled by lerna
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/*"
],
"scripts": {
"build": "npm run build --ws",
"build:types": "npm run build:types --ws --if-present",
"build": "npm run build --ws && npm run build:types",
"build:types": "npm run build:types --ws --if-present && tsc -b tsconfig.build.json",
"change": "changeset add",
"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",
@ -19,20 +19,30 @@
"report": "open ./coverage/lcov-report/index.html",
"set-entry": "npm exec --ws -c 'dot-json package.json main $(dot-json package.json $ENTRY)'",
"test": "mocha",
"test:watch": "npm run mocha -- --recursive --watch",
"test:update": "UPDATE_EXPECTATIONS=1 mocha --update",
"version": "changeset version && npm i --package-lock-only"
},
"devDependencies": {
"@babel/cli": "^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/preset-env": "^7.16.0",
"@babel/preset-typescript": "^7.22.5",
"@babel/register": "^7.16.0",
"@changesets/changelog-github": "^0.4.8",
"@changesets/cli": "^2.26.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",
"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",
"bluebird": "^3.7.2",
"c8": "^8.0.0",
@ -40,20 +50,30 @@
"cross-env": "^7.0.3",
"diffable-html": "^4.0.0",
"dot-json": "^1.2.2",
"esbuild": "^0.18.2",
"eslint": "^7.22.0",
"eslint-config-prettier": "^8.1.0",
"eslint-import-resolver-typescript": "^3.5.5",
"express": "^4.17.1",
"husky": "^8.0.0",
"it-fails": "^1.0.5",
"jsdom": "^19.0.0",
"jsdom-context-require": "^4.0.4",
"kleur": "^4.1.5",
"lint-staged": "^10.5.4",
"mocha": "^8.3.2",
"mocha-autotest": "^1.1.0",
"mocha-snap": "^5.0.0",
"prettier": "^2.8.8",
"pretty-format": "^29.5.0",
"rollup": "^3.25.1",
"shell-quote": "^1.7.2",
"sort-package-json": "^2.4.1",
"table": "^6.8.1",
"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 { TaglibLookup, Diagnostic } from "@marko/babel-utils";
import { Diagnostic, TaglibLookup } from "@marko/babel-utils";
import * as types from "./babel-types";
export { types };

View File

@ -216,6 +216,7 @@ declare global {
}
/** 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> {
/** Creates a Marko compatible output stream. */
createOut(): Out;

View File

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