Skip to content

Commit c645f17

Browse files
authored
Update configurePrerelease to not utilize ts internals (#23476)
* update configure nightly to not utilize ts internals * Nightly -> Prerelease * Remove alias
1 parent b00e370 commit c645f17

File tree

4 files changed

+31
-26
lines changed

4 files changed

+31
-26
lines changed

Gulpfile.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ for (const i in libraryTargets) {
215215
.pipe(gulp.dest(".")));
216216
}
217217

218-
const configureNightlyJs = path.join(scriptsDirectory, "configureNightly.js");
219-
const configureNightlyTs = path.join(scriptsDirectory, "configureNightly.ts");
218+
const configurePreleleaseJs = path.join(scriptsDirectory, "configurePrerelease.js");
219+
const configurePreleleaseTs = path.join(scriptsDirectory, "configurePrerelease.ts");
220220
const packageJson = "package.json";
221221
const versionFile = path.join(compilerDirectory, "core.ts");
222222

@@ -301,24 +301,25 @@ function getCompilerSettings(base: tsc.Settings, useBuiltCompiler?: boolean): ts
301301
return copy;
302302
}
303303

304-
gulp.task(configureNightlyJs, /*help*/ false, [], () => {
304+
gulp.task(configurePreleleaseJs, /*help*/ false, [], () => {
305305
const settings: tsc.Settings = {
306306
declaration: false,
307307
removeComments: true,
308308
noResolve: false,
309309
stripInternal: false,
310+
module: "commonjs"
310311
};
311-
return gulp.src(configureNightlyTs)
312+
return gulp.src(configurePreleleaseTs)
312313
.pipe(sourcemaps.init())
313314
.pipe(tsc(settings))
314-
.pipe(sourcemaps.write(path.dirname(configureNightlyJs)))
315-
.pipe(gulp.dest(path.dirname(configureNightlyJs)));
315+
.pipe(sourcemaps.write("."))
316+
.pipe(gulp.dest("./scripts"));
316317
});
317318

318319

319320
// Nightly management tasks
320-
gulp.task("configure-nightly", "Runs scripts/configureNightly.ts to prepare a build for nightly publishing", [configureNightlyJs], (done) => {
321-
exec(host, [configureNightlyJs, packageJson, versionFile], done, done);
321+
gulp.task("configure-nightly", "Runs scripts/configurePrerelease.ts to prepare a build for nightly publishing", [configurePreleleaseJs], (done) => {
322+
exec(host, [configurePreleleaseJs, "dev", packageJson, versionFile], done, done);
322323
});
323324
gulp.task("publish-nightly", "Runs `npm publish --tag next` to create a new nightly build on npm", ["LKG"], () => {
324325
return runSequence("clean", "useDebugMode", "runtests-parallel", (done) => {

Jakefile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ compileFile(/*outfile*/configurePrereleaseJs,
491491
/*prereqs*/[configurePrereleaseTs],
492492
/*prefixes*/[],
493493
/*useBuiltCompiler*/ false,
494-
{ noOutFile: false, generateDeclarations: false, keepComments: false, noResolve: false, stripInternal: false });
494+
{ noOutFile: true, generateDeclarations: false, keepComments: false, noResolve: false, stripInternal: false });
495495

496496
task("setDebugMode", function () {
497497
useDebugMode = true;

scripts/configurePrerelease.ts

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
/// <reference path="../src/compiler/sys.ts" />
1+
/// <reference types="node"/>
2+
import { normalize } from "path";
3+
import assert = require("assert");
4+
import { readFileSync, writeFileSync } from "fs";
5+
const args = process.argv.slice(2);
6+
27

38
/**
49
* A minimal description for a parsed package.json object.
@@ -10,28 +15,27 @@ interface PackageJson {
1015
}
1116

1217
function main(): void {
13-
const sys = ts.sys;
14-
if (sys.args.length < 3) {
15-
sys.write("Usage:" + sys.newLine)
16-
sys.write("\tnode configureNightly.js <dev|insiders> <package.json location> <file containing version>" + sys.newLine);
18+
if (args.length < 3) {
19+
console.log("Usage:");
20+
console.log("\tnode configureNightly.js <dev|insiders> <package.json location> <file containing version>");
1721
return;
1822
}
1923

20-
const tag = sys.args[0];
24+
const tag = args[0];
2125
if (tag !== "dev" && tag !== "insiders") {
2226
throw new Error(`Unexpected tag name '${tag}'.`);
2327
}
2428

2529
// Acquire the version from the package.json file and modify it appropriately.
26-
const packageJsonFilePath = ts.normalizePath(sys.args[1]);
27-
const packageJsonValue: PackageJson = JSON.parse(sys.readFile(packageJsonFilePath));
30+
const packageJsonFilePath = normalize(args[1]);
31+
const packageJsonValue: PackageJson = JSON.parse(readFileSync(packageJsonFilePath).toString());
2832

2933
const { majorMinor, patch } = parsePackageJsonVersion(packageJsonValue.version);
3034
const prereleasePatch = getPrereleasePatch(tag, patch);
3135

3236
// Acquire and modify the source file that exposes the version string.
33-
const tsFilePath = ts.normalizePath(sys.args[2]);
34-
const tsFileContents = ts.sys.readFile(tsFilePath);
37+
const tsFilePath = normalize(args[2]);
38+
const tsFileContents = readFileSync(tsFilePath).toString();
3539
const modifiedTsFileContents = updateTsFile(tsFilePath, tsFileContents, majorMinor, patch, prereleasePatch);
3640

3741
// Ensure we are actually changing something - the user probably wants to know that the update failed.
@@ -44,20 +48,20 @@ function main(): void {
4448
// Finally write the changes to disk.
4549
// Modify the package.json structure
4650
packageJsonValue.version = `${majorMinor}.${prereleasePatch}`;
47-
sys.writeFile(packageJsonFilePath, JSON.stringify(packageJsonValue, /*replacer:*/ undefined, /*space:*/ 4))
48-
sys.writeFile(tsFilePath, modifiedTsFileContents);
51+
writeFileSync(packageJsonFilePath, JSON.stringify(packageJsonValue, /*replacer:*/ undefined, /*space:*/ 4))
52+
writeFileSync(tsFilePath, modifiedTsFileContents);
4953
}
5054

5155
function updateTsFile(tsFilePath: string, tsFileContents: string, majorMinor: string, patch: string, nightlyPatch: string): string {
5256
const majorMinorRgx = /export const versionMajorMinor = "(\d+\.\d+)"/;
5357
const majorMinorMatch = majorMinorRgx.exec(tsFileContents);
54-
ts.Debug.assert(majorMinorMatch !== null, "", () => `The file seems to no longer have a string matching '${majorMinorRgx}'.`);
58+
assert(majorMinorMatch !== null, `The file seems to no longer have a string matching '${majorMinorRgx}'.`);
5559
const parsedMajorMinor = majorMinorMatch[1];
56-
ts.Debug.assert(parsedMajorMinor === majorMinor, "versionMajorMinor does not match.", () => `${tsFilePath}: '${parsedMajorMinor}'; package.json: '${majorMinor}'`);
60+
assert(parsedMajorMinor === majorMinor, `versionMajorMinor does not match. ${tsFilePath}: '${parsedMajorMinor}'; package.json: '${majorMinor}'`);
5761

5862
const versionRgx = /export const version = `\$\{versionMajorMinor\}\.(\d)(-dev)?`;/;
5963
const patchMatch = versionRgx.exec(tsFileContents);
60-
ts.Debug.assert(patchMatch !== null, "The file seems to no longer have a string matching", () => versionRgx.toString());
64+
assert(patchMatch !== null, "The file seems to no longer have a string matching " + versionRgx.toString());
6165
const parsedPatch = patchMatch[1];
6266
if (parsedPatch !== patch) {
6367
throw new Error(`patch does not match. ${tsFilePath}: '${parsedPatch}; package.json: '${patch}'`);
@@ -69,7 +73,7 @@ function updateTsFile(tsFilePath: string, tsFileContents: string, majorMinor: st
6973
function parsePackageJsonVersion(versionString: string): { majorMinor: string, patch: string } {
7074
const versionRgx = /(\d+\.\d+)\.(\d+)($|\-)/;
7175
const match = versionString.match(versionRgx);
72-
ts.Debug.assert(match !== null, "package.json 'version' should match", () => versionRgx.toString());
76+
assert(match !== null, "package.json 'version' should match " + versionRgx.toString());
7377
return { majorMinor: match[1], patch: match[2] };
7478
}
7579

0 commit comments

Comments
 (0)