-
Notifications
You must be signed in to change notification settings - Fork 274
Upgrade deno to v2 #321
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
Draft
danielpza
wants to merge
10
commits into
tsconfig:main
Choose a base branch
from
danielpza:deno-2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+275
−128
Draft
Upgrade deno to v2 #321
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
85b27d7
WIP deno v2
danielpza 2848c53
update v2 on CI
danielpza ca47353
WIP
danielpza 5aeed3c
update generate-recommend
danielpza 6929db7
udpate update-markdown-readme
danielpza f529342
format code with deno
danielpza 1d3a3ce
add .git-blame-ignore-rev
danielpza 8fb5fa3
add ci check to check formatting with deno
danielpza 9fdd631
migrate Deno.run() -> new Deno.Command().spawn()
danielpza a2aaa43
remove deno fmt --check step
danielpza File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 @@ | ||
f5293423738cc9d1d07e5bf87ae7a1b4cffff12f # https://github.com/tsconfig/bases/commit/f529342 | ||
This file contains hidden or 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 hidden or 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 hidden or 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,16 @@ | ||
{ | ||
"tasks": { | ||
"build": "deno run -RWN ./scripts/create-npm-packages.ts" | ||
}, | ||
"imports": { | ||
"@std/collections": "jsr:@std/collections@^1.1.2", | ||
"@std/io": "jsr:@std/io@^0.225.2", | ||
"@std/path": "jsr:@std/path@^1.1.1", | ||
"@std/semver": "jsr:@std/semver@^1.0.5", | ||
"@std/streams": "jsr:@std/streams@^1.0.10", | ||
"strip-json-comments": "npm:strip-json-comments@^5.0.3" | ||
}, | ||
"fmt": { | ||
"include": ["deno.json", "scripts/"] | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 |
---|---|---|
@@ -1,103 +1,128 @@ | ||
import * as path from "https://deno.land/std/path/mod.ts"; | ||
import stripJsonComments from "https://esm.sh/strip-json-comments"; | ||
import * as path from "jsr:@std/path"; | ||
import stripJsonComments from "npm:strip-json-comments"; | ||
|
||
for await (const tsconfigEntry of Deno.readDir("bases")) { | ||
if (!tsconfigEntry.isFile) continue | ||
const tsconfigFilePath = path.join("bases", tsconfigEntry.name) | ||
const name = path.basename(tsconfigEntry.name).replace(".json", "") | ||
if (!tsconfigEntry.isFile) continue; | ||
|
||
const tsconfigFilePath = path.join("bases", tsconfigEntry.name); | ||
const name = path.basename(tsconfigEntry.name).replace(".json", ""); | ||
|
||
// Make the folder | ||
const packagePath = path.join("packages", name) | ||
Deno.mkdirSync(packagePath, { recursive: true }) | ||
const packagePath = path.join("packages", name); | ||
Deno.mkdirSync(packagePath, { recursive: true }); | ||
|
||
// Copy over the template files | ||
const templateDir = "./template" | ||
const templateDir = "./template"; | ||
for await (const templateFile of Deno.readDir(templateDir)) { | ||
if (!templateFile.isFile) continue | ||
const templatedFile = path.join(templateDir, templateFile.name) | ||
Deno.copyFileSync(templatedFile, path.join(packagePath, templateFile.name)) | ||
if (!templateFile.isFile) continue; | ||
const templatedFile = path.join(templateDir, templateFile.name); | ||
Deno.copyFileSync(templatedFile, path.join(packagePath, templateFile.name)); | ||
} | ||
|
||
// Copy the create a tsconfig.json from the base json | ||
const newPackageTSConfigPath = path.join(packagePath, "tsconfig.json") | ||
Deno.copyFileSync(tsconfigFilePath, newPackageTSConfigPath) | ||
const tsconfigText = await Deno.readTextFile(newPackageTSConfigPath) | ||
const tsconfigJSON = JSON.parse(stripJsonComments(tsconfigText)) | ||
const newPackageTSConfigPath = path.join(packagePath, "tsconfig.json"); | ||
Deno.copyFileSync(tsconfigFilePath, newPackageTSConfigPath); | ||
|
||
const tsconfigText = await Deno.readTextFile(newPackageTSConfigPath); | ||
const tsconfigJSON = JSON.parse(stripJsonComments(tsconfigText)); | ||
|
||
// Drop `display` field in tsconfig.json for npm package | ||
await Deno.writeTextFile(newPackageTSConfigPath, tsconfigText.replace(/\s*"display.*/,'')) | ||
// Drop `display` field in tsconfig.json for npm package | ||
await Deno.writeTextFile( | ||
newPackageTSConfigPath, | ||
tsconfigText.replace(/\s*"display.*/, ""), | ||
); | ||
|
||
// Edit the package.json | ||
const packageText = await Deno.readTextFile(path.join(packagePath, "package.json")) | ||
const packageJSON = JSON.parse(packageText) | ||
packageJSON.name = `@tsconfig/${name}` | ||
packageJSON.description = `A base TSConfig for working with ${tsconfigJSON.display}.` | ||
packageJSON.keywords = ["tsconfig", name] | ||
const packageText = await Deno.readTextFile( | ||
path.join(packagePath, "package.json"), | ||
); | ||
const packageJSON = JSON.parse(packageText); | ||
packageJSON.name = `@tsconfig/${name}`; | ||
packageJSON.description = | ||
`A base TSConfig for working with ${tsconfigJSON.display}.`; | ||
packageJSON.keywords = ["tsconfig", name]; | ||
|
||
// Do some string replacements in the other templated files | ||
const replaceTextIn = ["README.md"] | ||
const replaceTextIn = ["README.md"]; | ||
for (const filenameToEdit of replaceTextIn) { | ||
const fileToEdit = path.join(packagePath, filenameToEdit) | ||
|
||
const defaultTitle = `A base TSConfig for working with ${tsconfigJSON.display}` | ||
const title = name !== "recommended" ? defaultTitle : "The recommended base for a TSConfig" | ||
const fileToEdit = path.join(packagePath, filenameToEdit); | ||
|
||
let packageText = await Deno.readTextFile(fileToEdit) | ||
const defaultTitle = | ||
`A base TSConfig for working with ${tsconfigJSON.display}`; | ||
const title = name !== "recommended" | ||
? defaultTitle | ||
: "The recommended base for a TSConfig"; | ||
|
||
let packageText = await Deno.readTextFile(fileToEdit); | ||
packageText = packageText.replace(/\[filename\]/g, name) | ||
.replace(/\[display_title\]/g, title) | ||
.replace(/\[tsconfig\]/g, Deno.readTextFileSync(newPackageTSConfigPath)) | ||
.replace(/\[display_title\]/g, title) | ||
.replace(/\[tsconfig\]/g, Deno.readTextFileSync(newPackageTSConfigPath)); | ||
|
||
// Inject readme-extra if any | ||
try { | ||
const readmeExtra = (await Deno.readTextFile(path.join("readme-extras", `${name}.md`))).trim() | ||
|
||
if (readmeExtra) | ||
packageText = packageText.replace(/\[readme-extra\]/g, `\n${readmeExtra}\n`) | ||
const readmeExtra = | ||
(await Deno.readTextFile(path.join("readme-extras", `${name}.md`))) | ||
.trim(); | ||
|
||
if (readmeExtra) { | ||
packageText = packageText.replace( | ||
/\[readme-extra\]/g, | ||
`\n${readmeExtra}\n`, | ||
); | ||
} | ||
} catch (error) { | ||
// NOOP, there is no extra readme | ||
// NOOP, there is no extra readme | ||
// console.log(error) | ||
} | ||
|
||
// Remove readme-extra placeholders if any | ||
packageText = packageText.replace(/\[readme-extra\]/g, '') | ||
packageText = packageText.replace(/\[readme-extra\]/g, ""); | ||
|
||
await Deno.writeTextFile(fileToEdit, packageText) | ||
}; | ||
await Deno.writeTextFile(fileToEdit, packageText); | ||
} | ||
|
||
// Bump the last version of the number from npm, | ||
// or use the _version in tsconfig if it's higher, | ||
// or default to 1.0.0 | ||
let version = tsconfigJSON._version || "1.0.0" | ||
let version = tsconfigJSON._version || "1.0.0"; | ||
try { | ||
const npmResponse = await fetch(`https://registry.npmjs.org/${packageJSON.name}`) | ||
const npmPackage = await npmResponse.json() | ||
const npmResponse = await fetch( | ||
`https://registry.npmjs.org/${packageJSON.name}`, | ||
); | ||
const npmPackage = await npmResponse.json(); | ||
|
||
const semverMarkers = npmPackage["dist-tags"].latest.split("."); | ||
const bumpedVersion = `${semverMarkers[0]}.${semverMarkers[1]}.${Number(semverMarkers[2]) + 1}`; | ||
const bumpedVersion = `${semverMarkers[0]}.${semverMarkers[1]}.${ | ||
Number(semverMarkers[2]) + 1 | ||
}`; | ||
if (isBumpedVersionHigher(version, bumpedVersion)) { | ||
version = bumpedVersion; | ||
} | ||
} catch (error) { | ||
// NOOP, this is for the first deploy | ||
// NOOP, this is for the first deploy | ||
// console.log(error) | ||
} | ||
|
||
packageJSON.version = version | ||
await Deno.writeTextFile(path.join(packagePath, "package.json"), JSON.stringify(packageJSON, null, " ")) | ||
|
||
packageJSON.version = version; | ||
await Deno.writeTextFile( | ||
path.join(packagePath, "package.json"), | ||
JSON.stringify(packageJSON, null, " "), | ||
); | ||
|
||
console.log("Built:", tsconfigEntry.name); | ||
} | ||
|
||
function isBumpedVersionHigher (packageJSONVersion: string, bumpedVersion: string) { | ||
const semverMarkersPackageJSON = packageJSONVersion.split('.') | ||
const semverMarkersBumped = bumpedVersion.split('.') | ||
function isBumpedVersionHigher( | ||
packageJSONVersion: string, | ||
bumpedVersion: string, | ||
) { | ||
const semverMarkersPackageJSON = packageJSONVersion.split("."); | ||
const semverMarkersBumped = bumpedVersion.split("."); | ||
for (let i = 0; i < 3; i++) { | ||
if (Number(semverMarkersPackageJSON[i]) > Number(semverMarkersBumped[i])) { | ||
return false | ||
return false; | ||
} | ||
} | ||
|
||
return true | ||
return true; | ||
} |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL'd