Skip to content

Commit

Permalink
[Windows] Facilitate building of OSD and plugins (opensearch-project#…
Browse files Browse the repository at this point in the history
…2601)

* [Windows] Replaces `rm -rf` with `remove.js`
* [dev/build] Facilitates using zipped archives of node releases
* [div/build] Introduces Windows as a platform
* [dev/build] Corrects cleaning of platform specific build artifacts
* [dev/build] Enhances the cleanup of downloaded node binaries
* [opensearch-dashboards-plugin] Removes prohibition on installing plugins on Windows
* [@osd/utils] Adds a method to standardize path references across platforms
* [dev/build] Standardize paths in tests
* [@osd/telemetry-tools] Normalizes the collection paths
* [plugins/url-forwarding] Fixes the usage of `normalizePath` across node and browser
* [@osd/pm] Allows symlink created for tests without elevated privileges on Windows
* [@osd/opensearch] Allows usage of Windows snapshots in integration tests
* [@osd/opensearch] Employs absolute paths in tests
* [@osd/apm-config-loader] Employs absolute paths in tests
* [core/server] Employs absolute and posix references to paths
* [@osd/optimizer] Standardize paths in tests
* [@osd/tests] Employs absolute paths in tests
* [@osd/pm] Standardize paths in project trees
* [plugins/telemetry] Accommodates the inability of Windows to create unreadable files for testing
* [@osd/config-schema] Normalize paths in tests
* [@osd/plugin-helpers] Standardize paths in tests
* [@osd/plugin-generator] Standardize paths in tests
* [Windows] Update changelog

Signed-off-by: Miki <[email protected]>
  • Loading branch information
AMoo-Miki authored Oct 21, 2022
1 parent 8d5e504 commit ec9e0b2
Show file tree
Hide file tree
Showing 71 changed files with 341 additions and 120 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
* [Multi DataSource] Make text content dynamically translated & update unit tests ([#2570](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2570))
* [Vis Builder] Change classname prefix wiz to vb ([#2581](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2581/files))
* [Vis Builder] Change wizard to vis_builder in file names and paths ([#2587](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2587))
* [Windows] Facilitate building and running OSD and plugins on Windows platforms ([#2601](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2601))
* [Multi DataSource] Address UX comments on Data source list and create page ([#2625](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2625))
* [Vis Builder] Rename wizard to visBuilder in i18n id and formatted message id ([#2635](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2635))

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"makelogs": "node scripts/makelogs",
"uiFramework:compileCss": "cd packages/osd-ui-framework && yarn compileCss",
"osd:watch": "node scripts/opensearch_dashboards --dev --logging.json=false",
"build:types": "rm -rf ./target/types && tsc --p tsconfig.types.json",
"build:types": "node scripts/remove.js ./target/types && tsc --p tsconfig.types.json",
"docs:acceptApiChanges": "node --max-old-space-size=6144 scripts/check_published_api_changes.js --accept",
"osd:bootstrap": "node scripts/build_ts_refs && node scripts/register_git_hook",
"spec_to_console": "node scripts/spec_to_console",
Expand Down Expand Up @@ -412,6 +412,7 @@
"mutation-observer": "^1.0.3",
"ngreact": "^0.5.1",
"nock": "12.0.3",
"node-stream-zip": "^1.15.0",
"normalize-path": "^3.0.0",
"nyc": "^15.1.0",
"pixelmatch": "^5.1.0",
Expand Down Expand Up @@ -461,4 +462,4 @@
"node": "14.20.0",
"yarn": "^1.21.1"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('getConfigurationFilePaths', () => {

expect(getConfigurationFilePaths(argv)).toEqual([
resolve(cwd, join('.', 'relative-path')),
'/absolute-path',
resolve('/absolute-path'),
]);
});

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions packages/osd-config-schema/src/errors/schema_error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* under the License.
*/

import { relative } from 'path';
import { relative, sep } from 'path';
import { SchemaError } from '.';

/**
Expand All @@ -37,7 +37,7 @@ import { SchemaError } from '.';
export const cleanStack = (stack: string) =>
stack
.split('\n')
.filter((line) => !line.includes('node_modules/') && !line.includes('internal/'))
.filter((line) => !line.includes('node_modules' + sep) && !line.includes('internal/'))
.map((line) => {
const parts = /.*\((.*)\).?/.exec(line) || [];

Expand All @@ -46,7 +46,11 @@ export const cleanStack = (stack: string) =>
}

const path = parts[1];
return line.replace(path, relative(process.cwd(), path));
// Cannot use `standardize` from `@osd/utils
let relativePath = relative(process.cwd(), path);
if (process.platform === 'win32') relativePath = relativePath.replace(/\\/g, '/');

return line.replace(path, relativePath);
})
.join('\n');

Expand Down
6 changes: 3 additions & 3 deletions packages/osd-opensearch-archiver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"devOnly": true
},
"scripts": {
"osd:bootstrap": "rm -rf target && tsc",
"osd:watch": "rm -rf target && tsc --watch"
"osd:bootstrap": "node ../../scripts/remove.js target && tsc",
"osd:watch": "node ../../scripts/remove.js target && tsc --watch"
},
"dependencies": {
"@osd/dev-utils": "1.0.0",
Expand All @@ -17,4 +17,4 @@
"devDependencies": {
"@types/elasticsearch": "^5.0.33"
}
}
}
8 changes: 5 additions & 3 deletions packages/osd-opensearch/src/artifact.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,14 @@ async function getArtifactSpecForSnapshotFromUrl(urlVersion, log) {
// issue: https://github.com/opensearch-project/OpenSearch-Dashboards/issues/475
const platform = process.platform === 'win32' ? 'windows' : process.platform;
const arch = process.arch === 'arm64' ? 'arm64' : 'x64';
if (platform !== 'linux') {
throw createCliError(`Snapshots are only available for Linux`);
const extension = process.platform === 'win32' ? 'zip' : 'tar.gz';

if (platform !== 'linux' && platform !== 'windows') {
throw createCliError(`Snapshots are only available for Linux and Windows`);
}

const latestUrl = `${DAILY_SNAPSHOTS_BASE_URL}/${desiredVersion}-SNAPSHOT`;
const latestFile = `opensearch-min-${desiredVersion}-SNAPSHOT-${platform}-${arch}-latest.tar.gz`;
const latestFile = `opensearch-min-${desiredVersion}-SNAPSHOT-${platform}-${arch}-latest.${extension}`;
const completeLatestUrl = `${latestUrl}/${latestFile}`;

let { abc, resp } = await verifySnapshotUrl(completeLatestUrl, log);
Expand Down
4 changes: 2 additions & 2 deletions packages/osd-opensearch/src/artifact.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ describe('Artifact', () => {
});
});

it('should throw when on a non-Linux platform', async () => {
it('should throw when on a non-Linux or non-Windows platform', async () => {
Object.defineProperties(process, {
platform: {
value: 'win32',
value: 'darwin',
},
arch: {
value: ORIGINAL_ARCHITECTURE,
Expand Down
4 changes: 2 additions & 2 deletions packages/osd-opensearch/src/utils/decompress.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ beforeEach(() => {
fs.copyFileSync(path.resolve(fixturesFolder, 'snapshot.tar.gz'), tarGzSnapshot);
});

afterEach(() => {
del.sync(tmpFolder, { force: true });
afterEach(async () => {
await del(tmpFolder, { force: true });
});

test('zip strips root directory', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jest.mock('fs', () => ({

const { extractConfigFiles } = require('./extract_config_files');
const fs = require('fs');
const path = require('path');

afterEach(() => {
jest.clearAllMocks();
Expand All @@ -55,7 +56,7 @@ test('copies file', () => {
extractConfigFiles(['path=/data/foo.yml'], '/opensearch');

expect(fs.readFileSync.mock.calls[0][0]).toEqual('/data/foo.yml');
expect(fs.writeFileSync.mock.calls[0][0]).toEqual('/opensearch/config/foo.yml');
expect(fs.writeFileSync.mock.calls[0][0]).toEqual(path.resolve('/opensearch/config/foo.yml'));
});

test('ignores file which does not exist', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* specific language governing permissions and limitations
* under the License.
*/
const path = require('path');

jest.mock('fs', () => ({
statSync: jest.fn().mockImplementation((path) => {
Expand Down Expand Up @@ -57,7 +58,7 @@ const { findMostRecentlyChanged } = require('./find_most_recently_changed');

test('returns newest file', () => {
const file = findMostRecentlyChanged('/data/*.yml');
expect(file).toEqual('/data/newest.yml');
expect(file).toEqual(path.resolve('/data/newest.yml'));
});

afterAll(() => {
Expand Down
6 changes: 5 additions & 1 deletion packages/osd-optimizer/src/common/bundle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* under the License.
*/

import { resolve } from 'path';
import { Bundle, BundleSpec, parseBundles } from './bundle';

jest.mock('fs');
Expand Down Expand Up @@ -88,13 +89,16 @@ it('provides the module count from the cache', () => {

it('parses bundles from JSON specs', () => {
const bundles = parseBundles(JSON.stringify([SPEC]));
let expectedCachePath = resolve('/foo/bar/target/.osd-optimizer-cache');
// Cannot use `standardize` from `@osd/util` due to mocking of fs
if (process?.platform === 'win32') expectedCachePath = expectedCachePath.replace(/\\/g, '\\\\');

expect(bundles).toMatchInlineSnapshot(`
Array [
Bundle {
"banner": undefined,
"cache": BundleCache {
"path": "/foo/bar/target/.osd-optimizer-cache",
"path": "${expectedCachePath}",
"state": undefined,
},
"contextDir": "/foo/bar",
Expand Down
15 changes: 11 additions & 4 deletions packages/osd-optimizer/src/optimizer/get_changes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@
* under the License.
*/

import path from 'path';

jest.mock('execa');

import { getChanges } from './get_changes';
import { standardize } from '@osd/dev-utils';

const execa: jest.Mock = jest.requireMock('execa');

Expand All @@ -56,12 +59,16 @@ it('parses git ls-files output', async () => {
};
});

const rootPath = path.resolve('/foo/bar/x/osd-optimizer') + path.sep;
const srcPath = path.join(rootPath, 'src') + path.sep;
const commonPath = path.join(srcPath, 'common') + path.sep;

await expect(getChanges('/foo/bar/x')).resolves.toMatchInlineSnapshot(`
Map {
"/foo/bar/x/osd-optimizer/package.json" => "modified",
"/foo/bar/x/osd-optimizer/src/common/bundle.ts" => "modified",
"/foo/bar/x/osd-optimizer/src/common/bundles.ts" => "deleted",
"/foo/bar/x/osd-optimizer/src/get_bundle_definitions.test.ts" => "deleted",
"${standardize(rootPath, false, true)}package.json" => "modified",
"${standardize(commonPath, false, true)}bundle.ts" => "modified",
"${standardize(commonPath, false, true)}bundles.ts" => "deleted",
"${standardize(srcPath, false, true)}get_bundle_definitions.test.ts" => "deleted",
}
`);
});
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,15 @@
import { createAbsolutePathSerializer } from '@osd/dev-utils';

import { getPluginBundles } from './get_plugin_bundles';
import path from 'path';

expect.addSnapshotSerializer(createAbsolutePathSerializer('/repo', '<repoRoot>'));
expect.addSnapshotSerializer(createAbsolutePathSerializer('/output', '<outputRoot>'));
expect.addSnapshotSerializer(createAbsolutePathSerializer(path.resolve('/output'), '<outputRoot>'));
expect.addSnapshotSerializer(createAbsolutePathSerializer('/outside/of/repo', '<outsideOfRepo>'));
expect.addSnapshotSerializer(
createAbsolutePathSerializer(path.resolve('/outside/of/repo'), '<outsideOfRepo>')
);

it('returns a bundle for core and each plugin', () => {
expect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,17 @@ import Path from 'path';

import del from 'del';
import execa from 'execa';
import { REPO_ROOT } from '@osd/utils';
import { createAbsolutePathSerializer } from '@osd/dev-utils';
import { REPO_ROOT, standardize, createAbsolutePathSerializer } from '@osd/dev-utils';
import globby from 'globby';

const GENERATED_DIR = Path.resolve(REPO_ROOT, `plugins`);
// Has to be a posix reference because it is used to generate glob patterns
const GENERATED_DIR = standardize(Path.resolve(REPO_ROOT, `plugins`), true);

expect.addSnapshotSerializer(createAbsolutePathSerializer());
expect.addSnapshotSerializer(
createAbsolutePathSerializer(
process?.platform === 'win32' ? standardize(REPO_ROOT, true) : REPO_ROOT
)
);

beforeEach(async () => {
await del([`${GENERATED_DIR}/**`, `!${GENERATED_DIR}`, `!${GENERATED_DIR}/.gitignore`], {
Expand Down
2 changes: 1 addition & 1 deletion packages/osd-plugin-helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"plugin-helpers": "bin/plugin-helpers.js"
},
"scripts": {
"osd:bootstrap": "rm -rf target && tsc",
"osd:bootstrap": "node ../../scripts/remove.js && tsc",
"osd:watch": "tsc --watch"
},
"dependencies": {
Expand Down
12 changes: 8 additions & 4 deletions packages/osd-plugin-helpers/src/integration_tests/build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ import Path from 'path';
import Fs from 'fs';

import execa from 'execa';
import { REPO_ROOT } from '@osd/utils';
import { createStripAnsiSerializer, createReplaceSerializer } from '@osd/dev-utils';
import {
REPO_ROOT,
standardize,
createStripAnsiSerializer,
createReplaceSerializer,
} from '@osd/dev-utils';
import extract from 'extract-zip';
import del from 'del';
import globby from 'globby';
Expand Down Expand Up @@ -78,7 +82,7 @@ it('builds a generated plugin into a viable archive', async () => {
expect(generateProc.all).toMatchInlineSnapshot(`
" succ 🎉
Your plugin has been created in plugins/foo_test_plugin
Your plugin has been created in ${standardize('plugins/foo_test_plugin', false, true)}
"
`);

Expand Down Expand Up @@ -165,7 +169,7 @@ it('builds a non-semver generated plugin into a viable archive', async () => {
expect(generateProc.all).toMatchInlineSnapshot(`
" succ 🎉
Your plugin has been created in plugins/foo_test_plugin
Your plugin has been created in ${standardize('plugins/foo_test_plugin', false, true)}
"
`);

Expand Down
3 changes: 2 additions & 1 deletion packages/osd-pm/src/utils/projects.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ describe('#getProjects', () => {

await promisify(symlink)(
join(__dirname, '__fixtures__/symlinked-plugins/corge'),
join(rootPlugins, 'corge')
join(rootPlugins, 'corge'),
'junction' // This parameter would only be used on Windows
);
});

Expand Down
3 changes: 2 additions & 1 deletion packages/osd-pm/src/utils/projects_tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import chalk from 'chalk';
import path from 'path';

import { standardize } from '@osd/utils';
import { Project } from './project';

const projectKey = Symbol('__project');
Expand Down Expand Up @@ -117,7 +118,7 @@ function createTreeStructure(tree: IProjectsTree): ITree {
// `foo/bar/baz` instead.
if (subtree.children && subtree.children.length === 1) {
const child = subtree.children[0];
const newName = chalk.dim(path.join(dir.toString(), child.name!));
const newName = chalk.dim(standardize(path.join(dir.toString(), child.name!), true));

children.push({
children: child.children,
Expand Down
4 changes: 2 additions & 2 deletions packages/osd-telemetry-tools/src/tools/ts_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import * as ts from 'typescript';
import { createFailError } from '@osd/dev-utils';
import * as path from 'path';
import { getProperty, getPropertyValue } from './utils';
import { getProperty, getPropertyValue, normalizePath } from './utils';
import { getDescriptor, Descriptor } from './serializer';

export function* traverseNodes(maybeNodes: ts.Node | ts.Node[]): Generator<ts.Node> {
Expand Down Expand Up @@ -205,7 +205,7 @@ export function* parseUsageCollection(
sourceFile: ts.SourceFile,
program: ts.Program
): Generator<ParsedUsageCollection> {
const relativePath = path.relative(process.cwd(), sourceFile.fileName);
const relativePath = normalizePath(path.relative(process.cwd(), sourceFile.fileName), false);
if (sourceHasUsageCollector(sourceFile)) {
for (const node of traverseNodes(sourceFile)) {
if (isMakeUsageCollectorFunction(node, sourceFile)) {
Expand Down
5 changes: 3 additions & 2 deletions packages/osd-telemetry-tools/src/tools/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ export function difference(actual: any, expected: any) {
return changes(actual, expected);
}

export function normalizePath(inputPath: string) {
return normalize(path.relative('.', inputPath));
export function normalizePath(inputPath: string, relativeToRoot: boolean = true) {
if (relativeToRoot) return normalize(path.relative('.', inputPath));
return normalize(inputPath);
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import { REPO_ROOT } from '@osd/dev-utils';
import { Lifecycle } from './lifecycle';
import { SuiteTracker } from './suite_tracker';

const DEFAULT_TEST_METADATA_PATH = join(REPO_ROOT, 'target', 'test_metadata.json');
const DEFAULT_TEST_METADATA_PATH = resolve(REPO_ROOT, 'target', 'test_metadata.json');
const MOCK_CONFIG_PATH = join('test', 'config.js');
const MOCK_TEST_PATH = join('test', 'apps', 'test.js');
const ENVS_TO_RESET = ['TEST_METADATA_PATH'];
Expand Down
Loading

0 comments on commit ec9e0b2

Please sign in to comment.