Skip to content

Commit

Permalink
Allow for inlining package.json when bundling (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrmarti committed Sep 6, 2022
1 parent 731ec51 commit 9dcb3fe
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 27 deletions.
6 changes: 3 additions & 3 deletions src/spec-node/devContainers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import * as path from 'path';
import * as crypto from 'crypto';

import { DockerResolverParameters, getPackageConfig, DevContainerAuthority, UpdateRemoteUserUIDDefault, BindMountConsistency } from './utils';
import { DockerResolverParameters, DevContainerAuthority, UpdateRemoteUserUIDDefault, BindMountConsistency } from './utils';
import { createNullPostCreate, finishBackgroundTasks, ResolverParameters, UserEnvProbe } from '../spec-common/injectHeadless';
import { getCLIHost, loadNativeModule } from '../spec-common/commonUtils';
import { resolve } from './configContainer';
Expand All @@ -15,7 +15,7 @@ import { promisify } from 'util';
import { LogLevel, LogDimensions, toErrorText, createCombinedLog, createTerminalLog, Log, makeLog, LogFormat, createJSONLog } from '../spec-utils/log';
import { dockerComposeCLIConfig } from './dockerCompose';
import { Mount } from '../spec-configuration/containerFeaturesConfiguration';
import { PackageConfiguration } from '../spec-utils/product';
import { getPackageConfig, PackageConfiguration } from '../spec-utils/product';
import { dockerBuildKitVersion } from '../spec-shutdown/dockerUtils';

export interface ProvisionOptions {
Expand Down Expand Up @@ -84,7 +84,7 @@ export async function createDockerParams(options: ProvisionOptions, disposables:
}
const extensionPath = path.join(__dirname, '..', '..');
const sessionStart = new Date();
const pkg = await getPackageConfig(extensionPath);
const pkg = getPackageConfig();
const output = createLog(options, pkg, sessionStart, disposables, options.omitLoggerHeader);

const appRoot = undefined;
Expand Down
7 changes: 4 additions & 3 deletions src/spec-node/devContainersSpecCLI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as path from 'path';
import yargs, { Argv } from 'yargs';

import { createDockerParams, createLog, launch, ProvisionOptions } from './devContainers';
import { createContainerProperties, createFeaturesTempFolder, envListToObj, getPackageConfig, isDockerFileConfig } from './utils';
import { createContainerProperties, createFeaturesTempFolder, envListToObj, isDockerFileConfig } from './utils';
import { URI } from 'vscode-uri';
import { ContainerError } from '../spec-common/errors';
import { Log, LogLevel, makeLog, mapLogLevel } from '../spec-utils/log';
Expand All @@ -29,13 +29,14 @@ import { featuresPackageHandler, featuresPackageOptions } from './featuresCLI/pa
import { featuresPublishHandler, featuresPublishOptions } from './featuresCLI/publish';
import { featuresInfoHandler, featuresInfoOptions } from './featuresCLI/info';
import { containerSubstitute } from '../spec-common/variableSubstitution';
import { getPackageConfig } from '../spec-utils/product';

const defaultDefaultUserEnvProbe: UserEnvProbe = 'loginInteractiveShell';

(async () => {

const packageFolder = path.join(__dirname, '..', '..');
const version = (await getPackageConfig(packageFolder)).version;
const version = getPackageConfig().version;
const argv = process.argv.slice(2);
const restArgs = argv[0] === 'exec' && argv[1] !== '--help'; // halt-at-non-option doesn't work in subcommands: https://github.com/yargs/yargs/issues/1417
const y = yargs([])
Expand Down Expand Up @@ -666,7 +667,7 @@ async function readConfiguration({
const cliHost = await getCLIHost(cwd, loadNativeModule);
const extensionPath = path.join(__dirname, '..', '..');
const sessionStart = new Date();
const pkg = await getPackageConfig(extensionPath);
const pkg = getPackageConfig();
output = createLog({
logLevel: mapLogLevel(logLevel),
logFormat,
Expand Down
6 changes: 2 additions & 4 deletions src/spec-node/featuresCLI/info.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import path from 'path';
import { Argv } from 'yargs';
import { getFeatureRef, getPublishedVersions } from '../../spec-configuration/containerFeaturesOCI';
import { Log, LogLevel, mapLogLevel } from '../../spec-utils/log';
import { getPackageConfig } from '../../spec-utils/product';
import { createLog } from '../devContainers';
import { UnpackArgv } from '../devContainersSpecCLI';
import { getPackageConfig } from '../utils';

export function featuresInfoOptions(y: Argv) {
return y
Expand All @@ -31,8 +30,7 @@ async function featuresInfo({
await Promise.all(disposables.map(d => d()));
};

const extensionPath = path.join(__dirname, '..', '..', '..');
const pkg = await getPackageConfig(extensionPath);
const pkg = getPackageConfig();

const output = createLog({
logLevel: mapLogLevel(inputLogLevel),
Expand Down
6 changes: 2 additions & 4 deletions src/spec-node/featuresCLI/package.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import path from 'path';
import { Argv } from 'yargs';
import { CLIHost, getCLIHost } from '../../spec-common/cliHost';
import { loadNativeModule } from '../../spec-common/commonUtils';
import { Log, mapLogLevel } from '../../spec-utils/log';
import { getPackageConfig } from '../../spec-utils/product';
import { createLog } from '../devContainers';
import { UnpackArgv } from '../devContainersSpecCLI';
import { getPackageConfig } from '../utils';
import { doFeaturesPackageCommand } from './packageCommandImpl';

const targetPositionalDescription = `
Expand Down Expand Up @@ -55,8 +54,7 @@ async function featuresPackage({
await Promise.all(disposables.map(d => d()));
};

const extensionPath = path.join(__dirname, '..', '..', '..');
const pkg = await getPackageConfig(extensionPath);
const pkg = getPackageConfig();

const cwd = process.cwd();
const cliHost = await getCLIHost(cwd, loadNativeModule);
Expand Down
3 changes: 1 addition & 2 deletions src/spec-node/featuresCLI/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ async function featuresPublish({
await Promise.all(disposables.map(d => d()));
};

const extensionPath = path.join(__dirname, '..', '..', '..');
const pkg = await getPackageConfig(extensionPath);
const pkg = getPackageConfig();

const cwd = process.cwd();
const cliHost = await getCLIHost(cwd, loadNativeModule);
Expand Down
4 changes: 1 addition & 3 deletions src/spec-node/featuresCLI/test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as path from 'path';
import { Argv } from 'yargs';
import { CLIHost, getCLIHost } from '../../spec-common/cliHost';
import { loadNativeModule } from '../../spec-common/commonUtils';
Expand Down Expand Up @@ -70,8 +69,7 @@ async function featuresTest({

const cwd = process.cwd();
const cliHost = await getCLIHost(cwd, loadNativeModule);
const extensionPath = path.join(__dirname, '..', '..', '..');
const pkg = await getPackageConfig(extensionPath);
const pkg = getPackageConfig();

const logLevel = mapLogLevel(inputLogLevel);

Expand Down
1 change: 0 additions & 1 deletion src/spec-node/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import { PackageConfiguration } from '../spec-utils/product';
export { getConfigFilePath, getDockerfilePath, isDockerFileConfig, resolveConfigFilePath } from '../spec-configuration/configuration';
export { uriToFsPath, parentURI } from '../spec-configuration/configurationCommonUtils';
export { CLIHostDocuments, Documents, createDocuments, Edit, fileDocuments, RemoteDocuments } from '../spec-configuration/editableFiles';
export { getPackageConfig } from '../spec-utils/product';


export type BindMountConsistency = 'consistent' | 'cached' | 'delegated' | undefined;
Expand Down
9 changes: 2 additions & 7 deletions src/spec-utils/product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,13 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as path from 'path';
import { readLocalFile } from './pfs';

export interface PackageConfiguration {
name: string;
publisher?: string;
version: string;
aiKey?: string;
}

export async function getPackageConfig(packageFolder: string): Promise<PackageConfiguration> {
const raw = await readLocalFile(path.join(packageFolder, 'package.json'), 'utf8');
return JSON.parse(raw);
export function getPackageConfig(): PackageConfiguration {
return require('../../package.json');
}
export const includeAllConfiguredFeatures = true;

0 comments on commit 9dcb3fe

Please sign in to comment.