Skip to content

Commit

Permalink
convert to ts 3.0
Browse files Browse the repository at this point in the history
wip convert to typescript 3.0

Add references field

wip ts 3.0

wip ts 3.0

wip ts 3.0

wip ts 3.0

wip ts 3.0

remove debug print

update to ts 3.0.3

Update to ts 3.0.3

Use webpack-env types properly

Clean up watch mode for metapackage

Use typescript@next for now

WIP update api docs building

WIP update api docs building

Fix handling of version in update-dependency

lint

wip cleanup

Remove references from examples

Clean up test watch:src scripts

Build all the docs

Add tdoptions files

add missing files

cleanup

formatting

Switch to ts 3.0.3 for now

Handle documentation index

Do not use references in examples

formatting

Update tests

lint

Add a header

Remove build compile from tests

lint

Fix composite

lint

lint updates

lint updates

prettier?

prettier?

Now prettier

No integrity

Try integrity again

Add prettier-changed files

cleanup

Clean up sibling scripts

fix webpack config

Fix docs runner

cleaup

Update handling of integrity

Cleanup

fix build utils

Fix integrity and theme building

Only add references if a src folder exists

Fix handling of targets check

Fix testutils

formatting

fix docs building

Add missing types

Add node types for tdoptions as well

clean up vega config

Fix typings
  • Loading branch information
blink1073 committed Sep 13, 2018
1 parent bbe152f commit 282ee23
Show file tree
Hide file tree
Showing 377 changed files with 15,062 additions and 1,260 deletions.
3 changes: 2 additions & 1 deletion .lintstagedrc
@@ -1,7 +1,8 @@
{
"linters": {
"**/*{.ts,.tsx,.js,.jsx,.css,.json,.md}": [
"prettier --write"
"prettier --write",
"git add"
],
"**/*{.ts,.tsx}": [
"tslint --fix -c tslint.json",
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -147,7 +147,7 @@ JupyterLab follows the Jupyter [Community Guides](https://jupyter.readthedocs.io

### Extending JupyterLab

To start developing your own extension, see our [developers documentation](https://jupyterlab.readthedocs.io/en/latest/developer/extension_dev.html) and [API docs](http://jupyterlab.github.io/jupyterlab/globals.html).
To start developing your own extension, see our [developers documentation](https://jupyterlab.readthedocs.io/en/latest/developer/extension_dev.html) and [API docs](http://jupyterlab.github.io/jupyterlab/index.html).

### License

Expand Down
7 changes: 4 additions & 3 deletions buildutils/package.json
Expand Up @@ -31,20 +31,21 @@
"url": "https://github.com/jupyterlab/jupyterlab.git"
},
"scripts": {
"build": "tsc",
"build": "tsc -p src",
"clean": "rimraf lib",
"prepublishOnly": "npm run build",
"watch": "tsc -w --listEmittedFiles"
"watch": "tsc -p src -w --listEmittedFiles"
},
"dependencies": {
"@phosphor/coreutils": "^1.3.0",
"child_process": "~1.0.2",
"fs-extra": "~4.0.2",
"glob": "~7.1.2",
"inquirer": "~3.3.0",
"package-json": "~5.0.0",
"path": "~0.12.7",
"sort-package-json": "~1.7.1",
"typescript": "~2.9.2"
"typescript": "~3.0.3"
},
"devDependencies": {
"@types/fs-extra": "~4.0.3",
Expand Down
25 changes: 1 addition & 24 deletions buildutils/src/add-sibling.ts
Expand Up @@ -50,28 +50,5 @@ if (fs.existsSync(path.join(packagePath, 'node_modules'))) {
fs.removeSync(path.join(packagePath, 'node_modules'));
}

// Get the package.json of the extension.
let data = utils.readJSONFile(path.join(packagePath, 'package.json'));

// Add the extension path to packages/metapackage/tsconfig.json
let tsconfigPath = path.join(
basePath,
'packages',
'metapackage',
'tsconfig.json'
);
let tsconfig = utils.readJSONFile(tsconfigPath);
tsconfig.compilerOptions.paths[data.name] = [
path.join('..', packageDirName, 'src')
];
fs.writeFileSync(tsconfigPath, JSON.stringify(tsconfig, null, 2) + '\n');

// Update the core jupyterlab build dependencies.
try {
utils.run('jlpm run integrity');
} catch (e) {
if (!process.env.TRAVIS_BRANCH) {
console.error(e);
process.exit(1);
}
}
utils.run('jlpm run integrity');
28 changes: 28 additions & 0 deletions buildutils/src/build-themes.ts
@@ -0,0 +1,28 @@
/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/

import * as fs from 'fs-extra';
import * as path from 'path';
import * as utils from './utils';

// Webpack all of the packages that have a theme dir.
utils.getCorePaths().forEach(pkgPath => {
const target = path.join(pkgPath, 'package.json');
if (!fs.existsSync(target)) {
return;
}
const data = require(target);
if (!data.jupyterlab) {
return;
}
const themeDir = data.jupyterlab.themeDir;
if (!themeDir) {
return;
}
if (!data.scripts['build:webpack']) {
return;
}
utils.run('jlpm run build:webpack', { cwd: pkgPath });
});
4 changes: 2 additions & 2 deletions buildutils/src/clean-packages.ts
Expand Up @@ -38,10 +38,10 @@ for (let i = 0; i < packageConfig.length; i++) {
*/
function handlePackage(packagePath: string): void {
// Read in the package.json.
packagePath = path.join(packagePath, 'package.json');
let packageJSONPath = path.join(packagePath, 'package.json');
let data: any;
try {
data = require(packagePath);
data = require(packageJSONPath);
} catch (e) {
console.log('skipping', packagePath);
return;
Expand Down
1 change: 1 addition & 0 deletions buildutils/src/create-theme.ts
Expand Up @@ -45,6 +45,7 @@ const plugin: JupyterLabPlugin<void> = {
activate: function(app: JupyterLab, manager: IThemeManager) {
manager.register({
name: '{{title}}',
isLight: true,
load: function() {
return manager.loadCSS('{{name}}/index.css');
},
Expand Down
43 changes: 42 additions & 1 deletion buildutils/src/ensure-package.ts
Expand Up @@ -27,6 +27,7 @@ export async function ensurePackage(
let missing = options.missing || [];
let unused = options.unused || [];
let messages: string[] = [];
let locals = options.locals || {};

// Verify dependencies are consistent.
let promises = Object.keys(deps).map(async name => {
Expand Down Expand Up @@ -59,7 +60,7 @@ export async function ensurePackage(
filenames = glob.sync(path.join(pkgPath, 'src/*.ts*'));
filenames = filenames.concat(glob.sync(path.join(pkgPath, 'src/**/*.ts*')));

if (filenames.length === 0) {
if (!fs.existsSync(path.join(pkgPath, 'src', 'tsconfig.json'))) {
if (utils.writePackageData(path.join(pkgPath, 'package.json'), data)) {
messages.push('Updated package.json');
}
Expand Down Expand Up @@ -108,6 +109,9 @@ export async function ensurePackage(

// Look for unused packages
Object.keys(deps).forEach(name => {
if (options.noUnused === false) {
return;
}
if (unused.indexOf(name) !== -1) {
return;
}
Expand All @@ -119,6 +123,33 @@ export async function ensurePackage(
}
});

// Handle references.
let references: { [key: string]: string } = Object.create(null);
Object.keys(deps).forEach(name => {
if (!(name in locals)) {
return;
}
const target = path.join(locals[name], 'src');
if (!fs.existsSync(target)) {
return;
}
references[name] = path.relative(path.join(pkgPath, 'src'), locals[name]);
references[name] = path.join(references[name], 'src');
});
if (
data.name.indexOf('test-') === -1 &&
data.name.indexOf('example-') === -1 &&
Object.keys(references).length > 0
) {
const tsConfigPath = path.join(pkgPath, 'src', 'tsconfig.json');
const tsConfigData = utils.readJSONFile(tsConfigPath);
tsConfigData.references = [];
Object.keys(references).forEach(name => {
tsConfigData.references.push({ path: references[name] });
});
utils.writeJSONFile(tsConfigPath, tsConfigData);
}

// Ensure dependencies and dev dependencies.
data.dependencies = deps;
data.devDependencies = devDeps;
Expand Down Expand Up @@ -164,6 +195,16 @@ export interface IEnsurePackageOptions {
* A list of dependencies that can be missing.
*/
missing?: string[];

/**
* A map of local package names and their relative path.
*/
locals?: { [key: string]: string };

/**
* Whether to enforce that dependencies get used. Default is true.
*/
noUnused?: boolean;
}

/**
Expand Down
74 changes: 33 additions & 41 deletions buildutils/src/ensure-repo.ts
Expand Up @@ -12,9 +12,8 @@
* Manage the metapackage meta package.
*/
import * as path from 'path';
import * as fs from 'fs-extra';
import * as utils from './utils';
import { ensurePackage } from './ensure-package';
import { ensurePackage, IEnsurePackageOptions } from './ensure-package';

// Data to ignore.
let MISSING: { [key: string]: string[] } = {
Expand All @@ -36,6 +35,7 @@ let pkgData: { [key: string]: any } = {};
let pkgPaths: { [key: string]: string } = {};
let pkgNames: { [key: string]: string } = {};
let depCache: { [key: string]: string } = {};
let locals: { [key: string]: string } = {};

/**
* Ensure the metapackage package.
Expand All @@ -44,20 +44,14 @@ let depCache: { [key: string]: string } = {};
*/
function ensureMetaPackage(): string[] {
let basePath = path.resolve('.');
let metaPackagePath = path.join(basePath, 'packages', 'metapackage');
let metaPackageJson = path.join(metaPackagePath, 'package.json');
let metaPackageData = utils.readJSONFile(metaPackageJson);
let indexPath = path.join(metaPackagePath, 'src', 'index.ts');
let index = fs
.readFileSync(indexPath, 'utf8')
.split('\r\n')
.join('\n');
let lines = index.split('\n').slice(0, 3);
let mpPath = path.join(basePath, 'packages', 'metapackage');
let mpJson = path.join(mpPath, 'package.json');
let mpData = utils.readJSONFile(mpJson);
let messages: string[] = [];
let seen: { [key: string]: boolean } = {};

utils.getCorePaths().forEach(pkgPath => {
if (path.resolve(pkgPath) === path.resolve(metaPackagePath)) {
if (path.resolve(pkgPath) === path.resolve(mpPath)) {
return;
}
let name = pkgNames[pkgPath];
Expand All @@ -69,40 +63,32 @@ function ensureMetaPackage(): string[] {
let valid = true;

// Ensure it is a dependency.
if (!metaPackageData.dependencies[name]) {
if (!mpData.dependencies[name]) {
valid = false;
metaPackageData.dependencies[name] = '^' + data.version;
mpData.dependencies[name] = '^' + data.version;
}

// Ensure it is in index.ts
if (index.indexOf(name) === -1) {
valid = false;
}
lines.push("import '" + name + "';");

if (!valid) {
messages.push(`Updated: ${name}`);
}
});

// Make sure there are no extra deps.
Object.keys(metaPackageData.dependencies).forEach(name => {
Object.keys(mpData.dependencies).forEach(name => {
if (!(name in seen)) {
messages.push(`Removing dependency: ${name}`);
delete metaPackageData.dependencies[name];
delete mpData.dependencies[name];
}
});

// Write the files.
if (messages.length > 0) {
utils.writePackageData(metaPackageJson, metaPackageData);
}
let newIndex = lines.join('\n') + '\n';
if (newIndex !== index) {
messages.push('Index changed');
fs.writeFileSync(indexPath, lines.join('\n') + '\n');
utils.writePackageData(mpJson, mpData);
}

// Update the global data.
pkgData[mpData.name] = mpData;

return messages;
}

Expand Down Expand Up @@ -207,17 +193,33 @@ export async function ensureIntegrity(): Promise<boolean> {
pkgData[data.name] = data;
pkgPaths[data.name] = pkgPath;
pkgNames[pkgPath] = data.name;
locals[data.name] = pkgPath;
});

// Update the metapackage.
let pkgMessages = ensureMetaPackage();
if (pkgMessages.length > 0) {
let pkgName = '@jupyterlab/metapackage';
if (!messages[pkgName]) {
messages[pkgName] = [];
}
messages[pkgName] = messages[pkgName].concat(pkgMessages);
}

// Validate each package.
for (let name in pkgData) {
let options = {
let options: IEnsurePackageOptions = {
pkgPath: pkgPaths[name],
data: pkgData[name],
depCache,
missing: MISSING[name],
unused: UNUSED[name]
unused: UNUSED[name],
locals
};

if (name === '@jupyterlab/metapackage') {
options.noUnused = false;
}
let pkgMessages = await ensurePackage(options);
if (pkgMessages.length > 0) {
messages[name] = pkgMessages;
Expand All @@ -231,16 +233,6 @@ export async function ensureIntegrity(): Promise<boolean> {
messages['top'] = ['Update package.json'];
}

// Handle the metapackage metapackage.
let pkgMessages = ensureMetaPackage();
if (pkgMessages.length > 0) {
let pkgName = '@jupyterlab/metapackage';
if (!messages[pkgName]) {
messages[pkgName] = [];
}
messages[pkgName] = messages[pkgName].concat(pkgMessages);
}

// Handle the JupyterLab application top package.
pkgMessages = ensureJupyterlab();
if (pkgMessages.length > 0) {
Expand All @@ -254,7 +246,7 @@ export async function ensureIntegrity(): Promise<boolean> {
// Handle any messages.
if (Object.keys(messages).length > 0) {
console.log(JSON.stringify(messages, null, 2));
if (process.env.TRAVIS_BRANCH || process.env.APPVEYOR) {
if ('--force' in process.argv) {
console.log(
'\n\nPlease run `jlpm run integrity` locally and commit the changes'
);
Expand Down
3 changes: 3 additions & 0 deletions buildutils/src/remove-dependency.ts
Expand Up @@ -45,3 +45,6 @@ function handlePackage(packagePath: string): void {
// Write the file back to disk.
utils.writePackageData(packagePath, data);
}

// Update the core jupyterlab build dependencies.
utils.run('jlpm run integrity');
21 changes: 1 addition & 20 deletions buildutils/src/remove-package.ts
Expand Up @@ -31,28 +31,9 @@ let packagePath = path.join(basePath, 'packages', target, 'package.json');
if (!fs.existsSync(packagePath)) {
packagePath = require.resolve(path.join(target, 'package.json'));
}
let data = utils.readJSONFile(packagePath);

// Remove the extension path from packages/metapackage/tsconfig.json
let tsconfigPath = path.join(
basePath,
'packages',
'metapackage',
'tsconfig.json'
);
let tsconfig = utils.readJSONFile(tsconfigPath);
tsconfig.compilerOptions.paths[data.name] = undefined;
fs.writeFileSync(tsconfigPath, JSON.stringify(tsconfig, null, 2) + '\n');

// Remove the package from the local tree.
fs.removeSync(path.dirname(packagePath));

// Update the core jupyterlab build dependencies.
try {
utils.run('npm run integrity');
} catch (e) {
if (!process.env.TRAVIS_BRANCH) {
console.error(e);
process.exit(1);
}
}
utils.run('npm run integrity');

0 comments on commit 282ee23

Please sign in to comment.