chore: properly package .ts and .d.ts files (#6257)

* fix: package .ts sources

* chore: add generating type defs

* chore: copy generated type defs into dist dir

* chore: fix adding generated def files

* chore: remove unnecessary imports

* chore: make handcrafted files reference generated

* chore: replace AnyDuringMigration with any

* chore: use replace instead of regex-replace

* chore: use value in config instead of magic strings

* chore: remove blockly.d.ts

* chore: update jsdocs

* chore: remove old references to typings
This commit is contained in:
Beka Westberg
2022-08-05 15:25:41 +00:00
committed by GitHub
parent fd127f6b60
commit 8f0a5ae6a8
16 changed files with 20 additions and 26173 deletions

View File

@@ -25,7 +25,7 @@ var closureDeps = require('google-closure-deps');
var argv = require('yargs').argv;
var rimraf = require('rimraf');
var {BUILD_DIR, DEPS_FILE, TEST_DEPS_FILE, TSC_OUTPUT_DIR} = require('./config');
var {BUILD_DIR, DEPS_FILE, TEST_DEPS_FILE, TSC_OUTPUT_DIR, TYPINGS_BUILD_DIR} = require('./config');
var {getPackageJson} = require('./helper_tasks');
////////////////////////////////////////////////////////////
@@ -317,7 +317,9 @@ const buildJavaScriptAndDeps = gulp.series(buildJavaScript, buildDeps);
* buildCompiled.
*/
function buildJavaScript(done) {
execSync(`tsc -outDir "${TSC_OUTPUT_DIR}"`, {stdio: 'inherit'});
execSync(
`tsc -outDir "${TSC_OUTPUT_DIR}" -declarationDir "${TYPINGS_BUILD_DIR}"`,
{stdio: 'inherit'});
done();
}

View File

@@ -32,7 +32,7 @@ exports.DEPS_FILE = path.join(exports.BUILD_DIR, 'deps.js');
exports.TEST_DEPS_FILE = path.join(exports.BUILD_DIR, 'deps.mocha.js');
// Directory to write typings output to.
exports.TYPINGS_BUILD_DIR = path.join(exports.BUILD_DIR, 'typings');
exports.TYPINGS_BUILD_DIR = path.join(exports.BUILD_DIR, 'declarations');
// Directory where typescript compiler output can be found.
// Matches the value in tsconfig.json: outDir

View File

@@ -14,6 +14,7 @@ gulp.replace = require('gulp-replace');
gulp.rename = require('gulp-rename');
gulp.insert = require('gulp-insert');
gulp.umd = require('gulp-umd');
gulp.replace = require('gulp-replace');
var path = require('path');
var fs = require('fs');
@@ -82,7 +83,7 @@ function checkBuildDir(done) {
* This task copies source files into the release directory.
*/
function packageSources() {
return gulp.src(['core/**/**.js', 'blocks/**.js', 'generators/**/**.js'],
return gulp.src(['core/**/**', 'blocks/**', 'generators/**/**'],
{base: '.'})
.pipe(gulp.dest(RELEASE_DIR));
};
@@ -377,13 +378,10 @@ function packageReadme() {
};
/**
* This task copies the typings/blockly.d.ts TypeScript definition
* file into the release directory. The bundled declaration file is
* referenced in package.json in the types property.
* As of Q4 2021 this simply copies the existing ts definition files, since
* generation through typescript-closure-tools does not work with goog.module.
* TODO(5621): Regenerate definition files and copy them into the release dir as
* needed.
* This task copies the generated .d.ts files in build/declarations and the
* hand-written .d.ts files in typings/ into the release directory. The main
* entrypoint file (index.d.ts) is referenced in package.json in the types
* property.
*/
function packageDTS() {
const handwrittenSrcs = [
@@ -391,6 +389,8 @@ function packageDTS() {
'typings/msg/msg.d.ts',
];
return gulp.src(handwrittenSrcs, {base: 'typings'})
.pipe(gulp.src(`${BUILD_DIR}/${TYPINGS_BUILD_DIR}/**/*.d.ts`))
.pipe(gulp.replace('AnyDuringMigration', 'any'))
.pipe(gulp.dest(RELEASE_DIR));
};

View File

@@ -153,10 +153,6 @@ const rebuildAll = gulp.series(
buildTasks.cleanBuildDir,
buildTasks.build,
buildTasks.checkinBuilt,
// TODO(5621): Re-enable once typings generation is fixed.
// typings.typings,
// typings.msgTypings,
// typings.checkinTypings,
);
// Package and publish to npm.