Commit 38b1b87e authored by Kenichi Kamiya's avatar Kenichi Kamiya Committed by Masum Reza
Browse files

typescript: prefer npmjs for src

parent 050d2ca1
Loading
Loading
Loading
Loading
+0 −15
Original line number Diff line number Diff line
Disable dprint on dstBundler

dprint fails on sandbox, because it requires internet access to install its
plugins.

--- a/scripts/dtsBundler.mjs
+++ b/scripts/dtsBundler.mjs
@@ -430,5 +430,5 @@
     return result.replace(/\r\n/g, "\n");
 }
 
-fs.writeFileSync(output, dprint(publicContents));
-fs.writeFileSync(internalOutput, dprint(internalContents));
+fs.writeFileSync(output, publicContents);
+fs.writeFileSync(internalOutput, internalContents);
+5445 −0

File added.

Preview size limit exceeded, changes collapsed.

+33 −37
Original line number Diff line number Diff line
{
  lib,
  buildNpmPackage,
  fetchFromGitHub,
  replaceVars,
  fetchurl,
  versionCheckHook,
  nix-update-script,
  writeShellApplication,
  nodejs,
  gnutar,
  nix-update,
  prefetch-npm-deps,
  gnused,
}:

buildNpmPackage (finalAttrs: {
  pname = "typescript";
  version = "5.8.3";

  src = fetchFromGitHub {
    owner = "microsoft";
    repo = "TypeScript";
    tag = "v${finalAttrs.version}";
    hash = "sha256-/XxjZO/pJLLAvsP7x4TOC+XDbOOR+HHmdpn+8qP77L8=";
  # Prefer npmjs over the GitHub repository for source code.
  # The TypeScript project typically publishes stable, versioned code to npmjs,
  # whereas GitHub tags may sometimes include development versions.
  # For example:
  #   - https://github.com/microsoft/TypeScript/pull/61218#issuecomment-2911264050
  #   - https://github.com/microsoft/TypeScript/pull/60150#issuecomment-2648791588, 5.8.3 includes this 5.9 breaking change
  src = fetchurl {
    url = "https://registry.npmjs.org/typescript/-/typescript-${finalAttrs.version}.tgz";
    hash = "sha256-cuddvrksLm65o0y1nXT6tcLubzKgMkqJQF9hZdWgg3Q=";
  };

  patches = [
    ./disable-dprint-dstBundler.patch

    # Should be removed in next 5.9.X TypeScript update: https://github.com/microsoft/TypeScript/pull/61218#issuecomment-2911264050
    (replaceVars ./revert-bump-to-v5.9.patch {
      inherit (finalAttrs) version;
    })
  ];

  postPatch = ''
    # The test run in the build script is redundant with checkPhase
    substituteInPlace package.json \
     --replace-fail ' && npm run build:tests' ""

    # Should be removed in next 5.9.X TypeScript update
    substituteInPlace src/compiler/corePublic.ts \
      --replace-fail 'versionMajorMinor = "5.9"' 'versionMajorMinor = "5.8"'
    substituteInPlace tests/baselines/reference/api/typescript.d.ts \
      --replace-fail 'versionMajorMinor = "5.9"' 'versionMajorMinor = "5.8"'

    # Imported from https://github.com/microsoft/TypeScript/blob/b504a1eed45e35b5f54694a1e0a09f35d0a5663c/.github/workflows/set-version.yaml#L75
    sed -i -e 's/const version\(: string\)\{0,1\} = .*;/const version = "${finalAttrs.version}" as string;/g' src/compiler/corePublic.ts
    ln -s '${./package-lock.json}' package-lock.json
  '';

  npmDepsHash = "sha256-BHJGezzZensC/WFsUumJSk6TYAqbS50Inuvw2nV5vUk=";
  npmDepsHash = "sha256-Y/+QPAVOQWKxrHBNEejC3UZrYKQNm7CleR0whFm2sLw=";

  postBuild = ''
    npx hereby lkg
  '';
  dontNpmBuild = true;

  nativeInstallCheckInputs = [
    versionCheckHook
@@ -56,11 +42,21 @@ buildNpmPackage (finalAttrs: {
  versionCheckProgramArg = "--version";

  passthru = {
    updateScript = nix-update-script {
      extraArgs = [
        "--version-regex=^v([\\d.]+)$"
    updateScript = lib.getExe (writeShellApplication {
      name = "${finalAttrs.pname}-updater";
      runtimeInputs = [
        nodejs
        gnutar
        nix-update
        prefetch-npm-deps
        gnused
      ];
      runtimeEnv = {
        PNAME = finalAttrs.pname;
        PKG_DIR = builtins.toString ./.;
      };
      text = builtins.readFile ./update.bash;
    });
  };

  meta = {
+0 −52
Original line number Diff line number Diff line
From fb5da5ae2622c4f7bb421f4d9ac6881b07ee220c Mon Sep 17 00:00:00 2001
From: Kenichi Kamiya <kachick1@gmail.com>
Date: Tue, 27 May 2025 16:09:56 +0900
Subject: [PATCH] Revert 1fdf78aee644afd2702d69c148754a7fc1aff910

This was an unintended slipped commit into v5.8.n
Should be removed until actually release 5.9

See https://github.com/microsoft/TypeScript/pull/61218#issuecomment-2911264050 for detail

Intentionally omitted to patch corePublic.ts and the d.ts
Including CRLF causes patching error in nixpkgs
---
 package-lock.json | 4 ++--
 package.json      | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/package-lock.json b/package-lock.json
index d4d2c055cc..63a0b372d2 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
 {
     "name": "typescript",
-    "version": "5.9.0",
+    "version": "@version@",
     "lockfileVersion": 2,
     "requires": true,
     "packages": {
         "": {
             "name": "typescript",
-            "version": "5.9.0",
+            "version": "@version@",
             "license": "Apache-2.0",
             "bin": {
                 "tsc": "bin/tsc",
diff --git a/package.json b/package.json
index ef2c80f8b9..0972bb4648 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
     "name": "typescript",
     "author": "Microsoft Corp.",
     "homepage": "https://www.typescriptlang.org/",
-    "version": "5.9.0",
+    "version": "@version@",
     "license": "Apache-2.0",
     "description": "TypeScript is a language for application scale JavaScript development",
     "keywords": [
-- 
2.49.0
+16 −0
Original line number Diff line number Diff line
cd "$PKG_DIR"

# Update lockfile
version="$(npm view typescript version)"
npm pack typescript
tar xvf "typescript-${version}.tgz"
mv package/package.json ./
npm install --package-lock-only
npmDepsHash=$(prefetch-npm-deps ./package-lock.json)
rm -rf ./package ./package.json ./"typescript-${version}.tgz"

cd -

# Update version and hashes
nix-update "$PNAME" --version "$version"
sed -E 's#\bnpmDepsHash = ".*?"#npmDepsHash = "'"$npmDepsHash"'"#' -i "$PKG_DIR/package.nix"