Skip to content
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

Adds global versions of the @ts/* deps #998

Merged
merged 4 commits into from
Aug 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/codeowners-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: Run Codeowners merge check
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
4 changes: 2 additions & 2 deletions packages/gatsby-remark-shiki-twoslash/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"lint": "tsdx lint"
},
"dependencies": {
"@typescript/twoslash": "1.0.2",
"@typescript/vfs": "1.2.0",
"@typescript/twoslash": "1.1.0",
"@typescript/vfs": "1.3.0",
"shiki": "^0.1.6",
"shiki-languages": "^0.1.6",
"shiki-twoslash": "0.8.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/shiki-twoslash/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"lint": "tsdx lint"
},
"dependencies": {
"@typescript/twoslash": "1.0.2",
"@typescript/vfs": "1.2.0",
"@typescript/twoslash": "1.1.0",
"@typescript/vfs": "1.3.0",
"shiki": "^0.1.6",
"shiki-languages": "^0.1.6",
"typescript": "*"
Expand Down
9 changes: 9 additions & 0 deletions packages/ts-twoslasher/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 1.1.0

- Adds a JS file into the npm tarball for using with a vanilla script tag, which sets `global.twoslash` with the main twoslash function. You need to include a copy of tsvfs beforehand.

Unpkg URLS:

- https://unpkg.com/browse/@typescript/vfs@dist/vfs.globals.js
- https://unpkg.com/browse/@typescript/twoslash@dist/twoslash.globals.js

## 1.0.2

- The `// @x`, `// ^?` and `// ^^^` comments ignore preceding whitespace
Expand Down
4 changes: 4 additions & 0 deletions packages/ts-twoslasher/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,10 @@ export interface TwoSlashReturn {

<!-- AUTO-GENERATED-CONTENT:END -->

## Using this Dependency

This package can be used as a commonjs import, an esmodule and directly via a script tag which edits the global namespace. All of these files are embedded inside the released packages.

## Local Development

Below is a list of commands you will probably find useful. You can get debug logs by running with the env var of `DEBUG="*"`.
Expand Down
7 changes: 4 additions & 3 deletions packages/ts-twoslasher/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@typescript/twoslash",
"version": "1.0.2",
"version": "1.1.0",
"license": "MIT",
"author": "TypeScript team",
"main": "dist/index.js",
Expand All @@ -11,7 +11,8 @@
],
"scripts": {
"start": "tsdx watch",
"build": "tsdx build && yarn readme",
"build": "tsdx build && yarn readme && yarn make-global",
"make-global": "node scripts/makeGlobals.js",
"readme": "yarn md-magic README.md --config ./scripts/inline-results.js && yarn prettier README.md --write",
"test": "tsdx test",
"lint": "tsdx lint"
Expand Down Expand Up @@ -39,7 +40,7 @@
"lz-string": false
},
"dependencies": {
"@typescript/vfs": "1.2.0",
"@typescript/vfs": "1.3.0",
"debug": "^4.1.1",
"lz-string": "^1.4.4"
}
Expand Down
29 changes: 29 additions & 0 deletions packages/ts-twoslasher/scripts/makeGlobals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// @ts-check

// Creates a web version of tstwoslash which sets a global of 'tstwoslash'.
// Relies on tsvfs already existing

const fs = require("fs")
const path = require("path")

const esm = fs.readFileSync(path.join(__dirname, "..", "dist", "twoslash.esm.js"), "utf8")
const body = esm
.replace("import {", "const {")
.replace("} from '@typescript/vfs';", "} = globals.tsvfs")
.replace("export {", "const twoslash = {")
const prefix = `
const getGlobal = function () {
if (typeof self !== 'undefined') { return self; }
if (typeof window !== 'undefined') { return window; }
if (typeof global !== 'undefined') { return global; }
throw new Error('unable to locate global object');
};

const globals = getGlobal();
if (typeof globals.tsvfs === 'undefined') throw new Error("Could not find tsvfs on the global object")
`

const suffix = `
globals.twoslash = twoslash`

fs.writeFileSync(path.join(__dirname, "..", "dist", "twoslash.globals.js"), prefix + body + suffix, "utf8")
8 changes: 8 additions & 0 deletions packages/typescript-vfs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
### 1.3

- Adds a JS file into the npm tarball for using with a vanilla script tag, which sets `global.tsvfs` with exported function.

Unpkg URLS:

- https://unpkg.com/browse/@typescript/vfs@dist/vfs.globals.js

### 1.2

Updates `createFSBackedSystem` to rely more on the default TypeScript system object which should see twoslash code samples re-using the node_modules from the local project.
Expand Down
4 changes: 4 additions & 0 deletions packages/typescript-vfs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,7 @@ program.emit()
// Now I can look at the AST for the .ts file too
const index = program.getSourceFile("index.ts")
```

## Using this Dependency

This package can be used as a commonjs import, an esmodule and directly via a script tag which edits the global namespace. All of these files are embedded inside the released packages.
6 changes: 4 additions & 2 deletions packages/typescript-vfs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@typescript/vfs",
"version": "1.2.0",
"version": "1.3.0",
"license": "MIT",
"author": "TypeScript team",
"homepage": "https://github.com/microsoft/TypeScript-Website/",
Expand All @@ -12,7 +12,9 @@
],
"scripts": {
"start": "tsdx watch",
"build": "tsdx build && cpy src/index.ts ../sandbox/src/vendor --rename=typescript-vfs.ts",
"build": "tsdx build && yarn make-for-website && yarn make-global",
"make-for-website": "cpy src/index.ts ../sandbox/src/vendor --rename=typescript-vfs.ts",
"make-global": "node scripts/makeGlobals.js",
"test": "tsdx test",
"lint": "tsdx lint"
},
Expand Down
22 changes: 22 additions & 0 deletions packages/typescript-vfs/scripts/makeGlobals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// @ts-check

// Creates a web version of tsvfs which sets a global of 'tsvfs'.

const fs = require("fs")
const path = require("path")

const esm = fs.readFileSync(path.join(__dirname, "..", "dist", "vfs.esm.js"), "utf8")
const body = esm.replace("export {", "const tsvfs = {")
const suffix = `
const getGlobal = function () {
if (typeof self !== 'undefined') { return self; }
if (typeof window !== 'undefined') { return window; }
if (typeof global !== 'undefined') { return global; }
throw new Error('unable to locate global object');
};

const globals = getGlobal();
globals.tsvfs = tsvfs;
`

fs.writeFileSync(path.join(__dirname, "..", "dist", "vfs.globals.js"), body + suffix, "utf8")
2 changes: 1 addition & 1 deletion packages/typescriptlang-org/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@mdx-js/react": "^1.5.5",
"@types/node-fetch": "^2.5.3",
"@types/react-helmet": "^5.0.15",
"@typescript/twoslash": "1.0.2",
"@typescript/twoslash": "1.1.0",
"canvas": "^2.6.1",
"gatsby": "^2.19.18",
"gatsby-plugin-catch-links": "^2.1.25",
Expand Down