|
@@ -68,6 +68,7 @@ export async function ensurePackage(
|
|
|
const cssImports = options.cssImports || [];
|
|
|
const cssModuleImports = options.cssModuleImports || [];
|
|
|
const differentVersions = options.differentVersions || [];
|
|
|
+ const isPrivate = data.private == true;
|
|
|
|
|
|
// Verify dependencies are consistent.
|
|
|
let promises = Object.keys(deps).map(async name => {
|
|
@@ -109,13 +110,7 @@ export async function ensurePackage(
|
|
|
filenames = filenames.concat(glob.sync(path.join(pkgPath, 'src/**/*.ts*')));
|
|
|
|
|
|
const tsConfigPath = path.join(pkgPath, 'tsconfig.json');
|
|
|
-
|
|
|
- if (!fs.existsSync(tsConfigPath)) {
|
|
|
- if (utils.writePackageData(path.join(pkgPath, 'package.json'), data)) {
|
|
|
- messages.push('Updated package.json');
|
|
|
- }
|
|
|
- return messages;
|
|
|
- }
|
|
|
+ const usesTS = fs.existsSync(tsConfigPath);
|
|
|
|
|
|
// Make sure typedoc config files are consistent
|
|
|
if (fs.existsSync(path.join(pkgPath, 'typedoc.json'))) {
|
|
@@ -184,8 +179,9 @@ export async function ensurePackage(
|
|
|
|
|
|
// Template the CSS index file.
|
|
|
if (
|
|
|
- cssImports.length > 0 ||
|
|
|
- fs.existsSync(path.join(pkgPath, 'style/base.css'))
|
|
|
+ usesTS &&
|
|
|
+ (cssImports.length > 0 ||
|
|
|
+ fs.existsSync(path.join(pkgPath, 'style/base.css')))
|
|
|
) {
|
|
|
const funcName = 'ensurePackage';
|
|
|
const cssIndexContents = [
|
|
@@ -209,8 +205,9 @@ export async function ensurePackage(
|
|
|
|
|
|
// Template the style module index file.
|
|
|
if (
|
|
|
- cssModuleImports.length > 0 ||
|
|
|
- fs.existsSync(path.join(pkgPath, 'style/base.css'))
|
|
|
+ usesTS &&
|
|
|
+ (cssModuleImports.length > 0 ||
|
|
|
+ fs.existsSync(path.join(pkgPath, 'style/base.css')))
|
|
|
) {
|
|
|
const funcName = 'ensurePackage';
|
|
|
const jsIndexContents = [
|
|
@@ -233,27 +230,29 @@ export async function ensurePackage(
|
|
|
}
|
|
|
|
|
|
// Look for unused packages
|
|
|
- Object.keys(deps).forEach(name => {
|
|
|
- if (options.noUnused === false) {
|
|
|
- return;
|
|
|
- }
|
|
|
- if (unused.indexOf(name) !== -1) {
|
|
|
- return;
|
|
|
- }
|
|
|
- const isTest = data.name.indexOf('test') !== -1;
|
|
|
- if (isTest) {
|
|
|
- const testLibs = ['jest', 'ts-jest', '@jupyterlab/testutils'];
|
|
|
- if (testLibs.indexOf(name) !== -1) {
|
|
|
+ if (usesTS) {
|
|
|
+ Object.keys(deps).forEach(name => {
|
|
|
+ if (options.noUnused === false) {
|
|
|
return;
|
|
|
}
|
|
|
- }
|
|
|
- if (names.indexOf(name) === -1) {
|
|
|
- const version = data.dependencies[name];
|
|
|
- messages.push(
|
|
|
- `Unused dependency: ${name}@${version}: remove or add to list of known unused dependencies for this package`
|
|
|
- );
|
|
|
- }
|
|
|
- });
|
|
|
+ if (unused.indexOf(name) !== -1) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const isTest = data.name.indexOf('test') !== -1;
|
|
|
+ if (isTest) {
|
|
|
+ const testLibs = ['jest', 'ts-jest', '@jupyterlab/testutils'];
|
|
|
+ if (testLibs.indexOf(name) !== -1) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (names.indexOf(name) === -1) {
|
|
|
+ const version = data.dependencies[name];
|
|
|
+ messages.push(
|
|
|
+ `Unused dependency: ${name}@${version}: remove or add to list of known unused dependencies for this package`
|
|
|
+ );
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
// Handle typedoc config output.
|
|
|
const tdOptionsPath = path.join(pkgPath, 'tdoptions.json');
|
|
@@ -277,7 +276,9 @@ export async function ensurePackage(
|
|
|
const ref = path.relative(pkgPath, locals[name]);
|
|
|
references[name] = ref.split(path.sep).join('/');
|
|
|
});
|
|
|
+
|
|
|
if (
|
|
|
+ usesTS &&
|
|
|
data.name.indexOf('example-') === -1 &&
|
|
|
Object.keys(references).length > 0
|
|
|
) {
|
|
@@ -290,7 +291,7 @@ export async function ensurePackage(
|
|
|
}
|
|
|
|
|
|
// Inherit from the base tsconfig.
|
|
|
- if (fs.existsSync(tsConfigPath)) {
|
|
|
+ if (usesTS) {
|
|
|
const tsConfigData = utils.readJSONFile(tsConfigPath);
|
|
|
tsConfigData.references = [];
|
|
|
Object.keys(references).forEach(name => {
|
|
@@ -354,13 +355,13 @@ export async function ensurePackage(
|
|
|
const schemas = glob.sync(
|
|
|
path.join(pkgPath, schemaDir || 'schema', '*.json')
|
|
|
);
|
|
|
- if (schemaDir && !schemas.length) {
|
|
|
+ if (schemaDir && !schemas.length && pkgPath.indexOf('examples') == -1) {
|
|
|
messages.push(`No schemas found in ${path.join(pkgPath, schemaDir)}.`);
|
|
|
} else if (!schemaDir && schemas.length) {
|
|
|
messages.push(`Schemas found, but no schema indicated in ${pkgPath}`);
|
|
|
}
|
|
|
for (const schema of schemas) {
|
|
|
- if (!published.has(schema)) {
|
|
|
+ if (!published.has(schema) && !isPrivate) {
|
|
|
messages.push(`Schema ${schema} not published in ${pkgPath}`);
|
|
|
}
|
|
|
}
|
|
@@ -368,7 +369,7 @@ export async function ensurePackage(
|
|
|
// Ensure that the `style` directories match what is in the `package.json`
|
|
|
const styles = glob.sync(path.join(pkgPath, 'style', '**/*.*'));
|
|
|
const styleIndex: { [key: string]: string } = {};
|
|
|
- if (styles.length > 0) {
|
|
|
+ if (styles.length && usesTS) {
|
|
|
// If there is no theme path, the style/styleModule must be defined
|
|
|
if (!data.jupyterlab?.themePath) {
|
|
|
if (data.style === undefined) {
|
|
@@ -421,14 +422,14 @@ export async function ensurePackage(
|
|
|
// Automatically add the style index files
|
|
|
if (data.files !== undefined && styleIndex[style] !== undefined) {
|
|
|
data.files.push(styleIndex[style]);
|
|
|
- } else {
|
|
|
+ } else if (!isPrivate) {
|
|
|
messages.push(`Style file ${style} not published in ${pkgPath}`);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// Ensure that sideEffects are declared, and that any styles are covered
|
|
|
- if (styles.length > 0) {
|
|
|
+ if (styles.length > 0 && !isPrivate) {
|
|
|
if (data.sideEffects === undefined) {
|
|
|
messages.push(
|
|
|
`Side effects not declared in ${pkgPath}, and styles are present.`
|
|
@@ -487,7 +488,7 @@ export async function ensurePackage(
|
|
|
found = true;
|
|
|
}
|
|
|
});
|
|
|
- if (!found) {
|
|
|
+ if (!found && !isPrivate) {
|
|
|
messages.push(`File ${basePath} not included in files`);
|
|
|
}
|
|
|
});
|
|
@@ -506,7 +507,7 @@ export async function ensurePackage(
|
|
|
found = true;
|
|
|
}
|
|
|
});
|
|
|
- if (!found) {
|
|
|
+ if (!found && !isPrivate) {
|
|
|
messages.push(`File ${targetPattern} not included in files`);
|
|
|
}
|
|
|
});
|
|
@@ -528,17 +529,28 @@ export async function ensurePackage(
|
|
|
delete data.gitHead;
|
|
|
|
|
|
// Ensure that there is a public access set, if the package is not private.
|
|
|
- if (data.private !== true) {
|
|
|
+ if (!isPrivate) {
|
|
|
data['publishConfig'] = { access: 'public' };
|
|
|
}
|
|
|
|
|
|
// Ensure there is not a prepublishOnly script.
|
|
|
// Since publishing is handled by an automated script and we don't
|
|
|
// Want to run individual scripts during publish.
|
|
|
- if (data.scripts.prepublishOnly) {
|
|
|
+ if (data.scripts?.prepublishOnly) {
|
|
|
delete data.scripts.prepublishOnly;
|
|
|
}
|
|
|
|
|
|
+ // If the package is not in `packages` or does not use `tsc` in its
|
|
|
+ // build script, add a `build:all` target
|
|
|
+ const buildScript = data.scripts?.build || '';
|
|
|
+ if (
|
|
|
+ buildScript &&
|
|
|
+ (pkgPath.indexOf('packages') == -1 || buildScript.indexOf('tsc') == -1) &&
|
|
|
+ !isPrivate
|
|
|
+ ) {
|
|
|
+ data.scripts['build:all'] = 'npm run build';
|
|
|
+ }
|
|
|
+
|
|
|
// Ensure the main module has an @packageDocumentation comment
|
|
|
let mainFile = path.join(pkgPath, 'src', 'index.ts');
|
|
|
if (!fs.existsSync(mainFile)) {
|