Sfoglia il codice sorgente

Move buildutils to scripts

Steven Silvester 7 anni fa
parent
commit
55de6e2137

+ 0 - 1
packages/buildutils/README.md

@@ -1 +0,0 @@
-# @jupyterlab/buildutils

+ 0 - 41
packages/buildutils/package.json

@@ -1,41 +0,0 @@
-{
-  "name": "@jupyterlab/buildutils",
-  "version": "0.1.2",
-  "description": "JupyterLab - Build Utilities",
-  "homepage": "https://github.com/jupyterlab/jupyterlab",
-  "bugs": {
-    "url": "https://github.com/jupyterlab/jupyterlab/issues"
-  },
-  "license": "BSD-3-Clause",
-  "author": "Project Jupyter",
-  "files": [
-    "lib/*.d.ts",
-    "lib/*.js.map",
-    "lib/*.js"
-  ],
-  "main": "lib/index.js",
-  "types": "lib/index.d.ts",
-  "directories": {
-    "lib": "lib/"
-  },
-  "repository": {
-    "type": "git",
-    "url": "https://github.com/jupyterlab/jupyterlab.git"
-  },
-  "scripts": {
-    "build": "tsc",
-    "clean": "rimraf lib",
-    "watch": "tsc -w"
-  },
-  "dependencies": {
-    "fs-extra": "~4.0.2",
-    "glob": "~7.1.2"
-  },
-  "devDependencies": {
-    "@types/fs-extra": "~4.0.3",
-    "@types/glob": "~5.0.33",
-    "@types/node": "~8.0.47",
-    "rimraf": "~2.6.2",
-    "typescript": "~2.4.2"
-  }
-}

+ 0 - 14
packages/buildutils/tsconfig.json

@@ -1,14 +0,0 @@
-{
-  "compilerOptions": {
-    "declaration": true,
-    "noImplicitAny": true,
-    "noEmitOnError": true,
-    "noUnusedLocals": true,
-    "module": "commonjs",
-    "moduleResolution": "node",
-    "target": "ES5",
-    "outDir": "./lib",
-    "lib": ["ES5", "ES2015.Promise", "DOM", "ES2015.Collection"]
-  },
-  "include": ["src/*"]
-}

+ 21 - 4
scripts/package.json

@@ -1,10 +1,27 @@
 {
-  "name": "@jupyterlab/scripts",
-  "version": "0.1.0",
-  "private": true,
-  "description": "JupyterLab - Scripts",
+  "name": "@jupyterlab/buildutils",
+  "version": "0.1.2",
+  "description": "JupyterLab - Build Utilities",
+  "homepage": "https://github.com/jupyterlab/jupyterlab",
+  "bugs": {
+    "url": "https://github.com/jupyterlab/jupyterlab/issues"
+  },
   "license": "BSD-3-Clause",
   "author": "Project Jupyter",
+  "files": [
+    "lib/*.d.ts",
+    "lib/*.js.map",
+    "lib/*.js"
+  ],
+  "main": "lib/index.js",
+  "types": "lib/index.d.ts",
+  "directories": {
+    "lib": "lib/"
+  },
+  "repository": {
+    "type": "git",
+    "url": "https://github.com/jupyterlab/jupyterlab.git"
+  },
   "scripts": {
     "build": "tsc",
     "clean": "rimraf lib",

+ 0 - 0
packages/buildutils/src/index.ts → scripts/src/build.ts


+ 173 - 0
scripts/src/ensure-package.ts

@@ -0,0 +1,173 @@
+/**
+ * Ensure the integrity of the packages in the repo.
+ *
+ * Ensure the core package version dependencies match everywhere.
+ * Ensure imported packages match dependencies.
+ * Ensure a consistent version of all packages.
+ * Manage the all-packages meta package.
+ */
+import * as fs from 'fs-extra';
+import * as glob from 'glob';
+import * as path from 'path';
+import * as ts from 'typescript';
+import { getDependency } from './get-dependency';
+import * as utils from './utils';
+
+/**
+ * Ensure the integrity of a package.
+ */
+export
+function ensurePackage(options: IEnsurePackageOptions): string[] {
+  let { data, pkgPath } = options;
+  let deps: { [key: string]: string } = data.dependencies;
+  let devDeps: { [key: string]: string } = data.devDependencies;
+  let seenDeps = options.depCache || {};
+  let missing = options.missing || [];
+  let unused = options.unused || [];
+  let messages: string[] = [];
+
+  // Verify dependencies are consistent.
+  Object.keys(deps).forEach(name => {
+    if (!(name in seenDeps)) {
+      seenDeps[name] = getDependency(name);
+    }
+    if (deps[name] !== seenDeps[name]) {
+      messages.push('Updated dependency: ' + name + '@' + seenDeps[name]);
+    }
+    deps[name] = seenDeps[name];
+  });
+
+  // Verify devDependencies are consistent.
+  Object.keys(devDeps).forEach(name => {
+    if (!(name in seenDeps)) {
+      seenDeps[name] = getDependency(name);
+    }
+    if (devDeps[name] !== seenDeps[name]) {
+      messages.push('Updated devDependency: ' + name + '@' + seenDeps[name]);
+    }
+    devDeps[name] = seenDeps[name];
+  });
+
+  // For TypeScript files, verify imports match dependencies.
+  let filenames: string[] = [];
+  filenames = glob.sync(path.join(pkgPath, 'src/*.ts*'));
+  filenames = filenames.concat(glob.sync(path.join(pkgPath, 'src/**/*.ts*')));
+
+  if (filenames.length === 0) {
+    if (utils.ensurePackageData(data, path.join(pkgPath, 'package.json'))) {
+      messages.push('Update package.json');
+    }
+    return messages;
+  }
+
+  let imports: string[] = [];
+
+  // Extract all of the imports from the TypeScript files.
+  filenames.forEach(fileName => {
+    let sourceFile = ts.createSourceFile(fileName,
+        fs.readFileSync(fileName).toString(), (ts.ScriptTarget as any).ES6,
+        /*setParentNodes */ true);
+    imports = imports.concat(getImports(sourceFile));
+  });
+  let names: string[] = Array.from(new Set(imports)).sort();
+  names = names.map(function(name) {
+    let parts = name.split('/');
+    if (name.indexOf('@') === 0) {
+      return parts[0] + '/' + parts[1];
+    }
+    return parts[0];
+  });
+
+  // Look for imports with no dependencies.
+  names.forEach(name => {
+    if (missing.indexOf(name) !== -1) {
+      return;
+    }
+    if (name === '.' || name === '..') {
+      return;
+    }
+    if (!deps[name]) {
+      messages.push('Missing dependency: ' + name);
+      if (!(name in seenDeps)) {
+        seenDeps[name] = getDependency(name);
+      }
+      deps[name] = seenDeps[name];
+    }
+  });
+
+  // Look for unused packages
+  Object.keys(deps).forEach(name => {
+    if (unused.indexOf(name) !== -1) {
+      return;
+    }
+    if (names.indexOf(name) === -1) {
+      messages.push('Unused dependency: ' + name);
+      delete data.dependencies[name];
+    }
+  });
+
+  if (utils.ensurePackageData(data, path.join(pkgPath, 'package.json'))) {
+    messages.push('Update package.json');
+  }
+  return messages;
+}
+
+
+/**
+ * The options used to ensure a package.
+ */
+export
+interface IEnsurePackageOptions {
+  /**
+   * The path to the package.
+   */
+  pkgPath: string;
+
+  /**
+   * The package data.
+   */
+  data: any;
+
+  /**
+   * The cache of dependency versions by package.
+   */
+  depCache?: { [key: string]: string };
+
+  /**
+   * A list of depedencies that can be unused.
+   */
+  unused?: string[];
+
+  /**
+   * A list of dependencies that can be missing.
+   */
+  missing?: string[];
+}
+
+
+/**
+ * Extract the module imports from a TypeScript source file.
+ *
+ * @param sourceFile - The path to the source file.
+ *
+ * @returns An array of package names.
+ */
+function getImports(sourceFile: ts.SourceFile): string[] {
+  let imports: string[] = [];
+  handleNode(sourceFile);
+
+  function handleNode(node: any): void {
+    switch (node.kind) {
+      case ts.SyntaxKind.ImportDeclaration:
+        imports.push(node.moduleSpecifier.text);
+        break;
+      case ts.SyntaxKind.ImportEqualsDeclaration:
+        imports.push(node.moduleReference.expression.text);
+        break;
+      default:
+        // no-op
+    }
+    ts.forEachChild(node, handleNode);
+  }
+  return imports;
+}

+ 14 - 134
scripts/src/ensure-integrity.ts → scripts/src/ensure-repo.ts

@@ -6,13 +6,11 @@
  * Ensure a consistent version of all packages.
  * Manage the all-packages meta package.
  */
-import childProcess = require('child_process');
-import path = require('path');
-import glob = require('glob');
-import ts = require('typescript');
-import fs = require('fs-extra');
-import getDependency = require('./get-dependency');
-import utils = require('./utils');
+import * as childProcess from 'child_process';
+import * as path from 'path';
+import * as fs from 'fs-extra';
+import * as utils from './utils';
+import { ensurePackage } from './ensure-package';
 
 
 // Data to ignore.
@@ -30,132 +28,7 @@ let UNUSED: { [key: string]: string[] } = {
 let pkgData: { [key: string]: any } = {};
 let pkgPaths: { [key: string]: string } = {};
 let pkgNames: { [key: string]: string } = {};
-let seenDeps: { [key: string]: string } = {};
-
-
-/**
- * Ensure the integrity of a package.
- */
-function ensurePackage(pkgName: string): string[] {
-  let dname = pkgPaths[pkgName];
-  let data = pkgData[pkgName];
-  let deps: { [key: string]: string } = data.dependencies;
-  let devDeps: { [key: string]: string } = data.devDependencies;
-  let messages: string[] = [];
-
-  // Verify dependencies are consistent.
-  Object.keys(deps).forEach(name => {
-    if (!(name in seenDeps)) {
-      seenDeps[name] = getDependency.getDependency(name);
-    }
-    if (deps[name] !== seenDeps[name]) {
-      messages.push('Updated dependency: ' + name + '@' + seenDeps[name]);
-    }
-    deps[name] = seenDeps[name];
-  });
-
-  // Verify devDependencies are consistent.
-  Object.keys(devDeps).forEach(name => {
-    if (!(name in seenDeps)) {
-      seenDeps[name] = getDependency.getDependency(name);
-    }
-    if (devDeps[name] !== seenDeps[name]) {
-      messages.push('Updated devDependency: ' + name + '@' + seenDeps[name]);
-    }
-    devDeps[name] = seenDeps[name];
-  });
-
-  // For TypeScript files, verify imports match dependencies.
-  let filenames: string[] = [];
-  filenames = glob.sync(path.join(dname, 'src/*.ts*'));
-  filenames = filenames.concat(glob.sync(path.join(dname, 'src/**/*.ts*')));
-
-  if (filenames.length === 0) {
-    if (utils.ensurePackageData(data, path.join(dname, 'package.json'))) {
-      messages.push('Update package.json');
-    }
-    return messages;
-  }
-
-  let imports: string[] = [];
-
-  // Extract all of the imports from the TypeScript files.
-  filenames.forEach(fileName => {
-    let sourceFile = ts.createSourceFile(fileName,
-        fs.readFileSync(fileName).toString(), (ts.ScriptTarget as any).ES6,
-        /*setParentNodes */ true);
-    imports = imports.concat(getImports(sourceFile));
-  });
-  let names: string[] = Array.from(new Set(imports)).sort();
-  names = names.map(function(name) {
-    let parts = name.split('/');
-    if (name.indexOf('@') === 0) {
-      return parts[0] + '/' + parts[1];
-    }
-    return parts[0];
-  });
-
-  // Look for imports with no dependencies.
-  names.forEach(name => {
-    if (MISSING[pkgName] && MISSING[pkgName].indexOf(name) !== -1) {
-      return;
-    }
-    if (name === '.' || name === '..') {
-      return;
-    }
-    if (!deps[name]) {
-      messages.push('Missing dependency: ' + name);
-      if (!(name in seenDeps)) {
-        seenDeps[name] = getDependency.getDependency(name);
-      }
-      deps[name] = seenDeps[name];
-    }
-  });
-
-  // Look for unused packages
-  Object.keys(deps).forEach(name => {
-    if (UNUSED[pkgName] && UNUSED[pkgName].indexOf(name) !== -1) {
-      return;
-    }
-    if (names.indexOf(name) === -1) {
-      messages.push('Unused dependency: ' + name);
-      delete data.dependencies[name];
-    }
-  });
-
-  if (utils.ensurePackageData(data, path.join(dname, 'package.json'))) {
-    messages.push('Update package.json');
-  }
-  return messages;
-}
-
-
-/**
- * Extract the module imports from a TypeScript source file.
- *
- * @param sourceFile - The path to the source file.
- *
- * @returns An array of package names.
- */
-function getImports(sourceFile: ts.SourceFile): string[] {
-  let imports: string[] = [];
-  handleNode(sourceFile);
-
-  function handleNode(node: any): void {
-    switch (node.kind) {
-      case ts.SyntaxKind.ImportDeclaration:
-        imports.push(node.moduleSpecifier.text);
-        break;
-      case ts.SyntaxKind.ImportEqualsDeclaration:
-        imports.push(node.moduleReference.expression.text);
-        break;
-      default:
-        // no-op
-    }
-    ts.forEachChild(node, handleNode);
-  }
-  return imports;
-}
+let depCache: { [key: string]: string } = {};
 
 
 /**
@@ -306,7 +179,14 @@ function ensureIntegrity(): void {
 
   // Validate each package.
   for (let name in pkgData) {
-    let pkgMessages = ensurePackage(name);
+    let options = {
+      pkgPath: pkgPaths[name],
+      data: pkgData[name],
+      depCache,
+      missing: MISSING[name],
+      unused: UNUSED[name]
+    };
+    let pkgMessages = ensurePackage(options);
     if (pkgMessages.length > 0) {
       messages[name] = pkgMessages;
     }

+ 9 - 0
scripts/src/index.ts

@@ -0,0 +1,9 @@
+/*-----------------------------------------------------------------------------
+| Copyright (c) Jupyter Development Team.
+| Distributed under the terms of the Modified BSD License.
+|----------------------------------------------------------------------------*/
+
+export * from './build';
+export * from './ensure-package';
+export * from './get-dependency';
+export * from './utils';