Skip to content

Commit

Permalink
chore(NA): enable preserve symlinks for ts without breaking packages …
Browse files Browse the repository at this point in the history
…development (#95433)

* chore(NA): move elastic-datemath into a ts package

* chore(NA): finish elastic-datemath

* chore(NA): finish elastic-datemath

* chore(NA): source folder for elastic-datemath

* chore(NA): add source-maps ace, analytics, apm-config-loader and apm-utils packages

* chore(NA): add sourcemaps to packages on typescript

* chore(NA): move test fixtures within source

* chore(NA): correct exclusions on packages

* chore(NA): correct package.json on all packages

* chore(NA): correct package.json on all packages

* chore(NA): complete kbn pm

* chore(NA): default export on elastic-datemath

* chore(NA): include logs on kbn-logging

* chore(NA): update bundle ref module to last code used in the webpack upstream

* chore(NA): update bundle ref module to last code used in the webpack upstream - refactored

* chore(NA): remove override method for exportsArgument

* fix(NA): typechecking problems by use @internal at javascript import sources on kbn-test package

* fix(NA): typescript projects check

* fix(NA): run optimizer integration tests from source

* chore(NA): fix usage from target for kbn optimizer

* chore(NA): path on tsconfig

* chore(NA): move tsignore into ts-expect-error

* chore(NA): include souce maps on kbn cli dev

* chore(NA): include souce maps on kbn-crypto, kbn-server-http-tools and kbn-telemetry-tools

* chore(NA): add issue links into the ts-expect-error comments
  • Loading branch information
mistic authored Mar 30, 2021
1 parent c35ef75 commit 50313f7
Show file tree
Hide file tree
Showing 93 changed files with 389 additions and 218 deletions.
File renamed without changes.
51 changes: 0 additions & 51 deletions packages/elastic-datemath/index.d.ts

This file was deleted.

8 changes: 6 additions & 2 deletions packages/elastic-datemath/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"version": "5.0.3",
"description": "elasticsearch datemath parser, used in kibana",
"license": "Apache-2.0",
"main": "index.js",
"typings": "index.d.ts"
"main": "./target/index.js",
"types": "./target/index.d.ts",
"scripts": {
"build": "../../node_modules/.bin/tsc",
"kbn:bootstrap": "yarn build"
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,18 @@
* under the License.
*/

const moment = require('moment');
import moment from 'moment';

export type Unit = 'ms' | 's' | 'm' | 'h' | 'd' | 'w' | 'M' | 'y';
export type UnitsMap = {
[k in Unit]: {
weight: number;
type: 'calendar' | 'fixed' | 'mixed';
base: number;
};
};

const unitsMap = {
export const unitsMap: UnitsMap = {
ms: { weight: 1, type: 'fixed', base: 1 },
s: { weight: 2, type: 'fixed', base: 1000 },
m: { weight: 3, type: 'mixed', base: 1000 * 60 },
Expand All @@ -30,25 +39,32 @@ const unitsMap = {
// q: { weight: 8, type: 'calendar' }, // TODO: moment duration does not support quarter
y: { weight: 9, type: 'calendar', base: NaN },
};
const units = Object.keys(unitsMap).sort((a, b) => unitsMap[b].weight - unitsMap[a].weight);
const unitsDesc = [...units];
const unitsAsc = [...units].reverse();

const isDate = (d) => Object.prototype.toString.call(d) === '[object Date]';
export const units: Unit[] = Object.keys(unitsMap).sort(
(a, b) => unitsMap[b as Unit].weight - unitsMap[a as Unit].weight
) as Unit[];
export const unitsDesc: Unit[] = [...units] as Unit[];
export const unitsAsc: Unit[] = [...units].reverse() as Unit[];

const isValidDate = (d) => isDate(d) && !isNaN(d.valueOf());
const isDate = (d: string) => Object.prototype.toString.call(d) === '[object Date]';
const isValidDate = (d: string) => isDate(d) && !isNaN(d.valueOf() as any);

/*
* This is a simplified version of elasticsearch's date parser.
* If you pass in a momentjs instance as the third parameter the calculation
* will be done using this (and its locale settings) instead of the one bundled
* with this library.
*/
function parse(text, { roundUp = false, momentInstance = moment, forceNow } = {}) {
export function parse(
input: string,
options: { roundUp?: boolean; momentInstance?: typeof moment; forceNow?: Date } = {}
) {
const text = input;
const { roundUp = false, momentInstance = moment, forceNow } = options;

if (!text) return undefined;
if (momentInstance.isMoment(text)) return text;
if (isDate(text)) return momentInstance(text);
if (forceNow !== undefined && !isValidDate(forceNow)) {
if (forceNow !== undefined && !isValidDate(forceNow as any)) {
throw new Error('forceNow must be a valid Date');
}

Expand Down Expand Up @@ -80,7 +96,7 @@ function parse(text, { roundUp = false, momentInstance = moment, forceNow } = {}
return parseDateMath(mathString, time, roundUp);
}

function parseDateMath(mathString, time, roundUp) {
function parseDateMath(mathString: string, time: moment.Moment, roundUp: boolean) {
const dateTime = time;
const len = mathString.length;
let i = 0;
Expand All @@ -89,7 +105,7 @@ function parseDateMath(mathString, time, roundUp) {
const c = mathString.charAt(i++);
let type;
let num;
let unit;
let unit: Unit;

if (c === '/') {
type = 0;
Expand All @@ -101,13 +117,13 @@ function parseDateMath(mathString, time, roundUp) {
return;
}

if (isNaN(mathString.charAt(i))) {
if (isNaN(mathString.charAt(i) as any)) {
num = 1;
} else if (mathString.length === 2) {
num = mathString.charAt(i);
} else {
const numFrom = i;
while (!isNaN(mathString.charAt(i))) {
while (!isNaN(mathString.charAt(i) as any)) {
i++;
if (i >= len) return;
}
Expand All @@ -121,7 +137,7 @@ function parseDateMath(mathString, time, roundUp) {
}
}

unit = mathString.charAt(i++);
unit = mathString.charAt(i++) as Unit;

// append additional characters in the unit
for (let j = i; j < len; j++) {
Expand All @@ -138,21 +154,22 @@ function parseDateMath(mathString, time, roundUp) {
return;
} else {
if (type === 0) {
if (roundUp) dateTime.endOf(unit);
else dateTime.startOf(unit);
if (roundUp) dateTime.endOf(unit as any);
else dateTime.startOf(unit as any);
} else if (type === 1) {
dateTime.add(num, unit);
dateTime.add(num as any, unit);
} else if (type === 2) {
dateTime.subtract(num, unit);
dateTime.subtract(num as any, unit);
}
}
}

return dateTime;
}

module.exports = {
parse: parse,
// eslint-disable-next-line import/no-default-export
export default {
parse,
unitsMap: Object.freeze(unitsMap),
units: Object.freeze(units),
unitsAsc: Object.freeze(unitsAsc),
Expand Down
12 changes: 10 additions & 2 deletions packages/elastic-datemath/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"tsBuildInfoFile": "../../build/tsbuildinfo/packages/elastic-datemath"
"incremental": false,
"outDir": "./target",
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"sourceRoot": "../../../../packages/elastic-datemath/src",
"types": [
"node"
]
},
"include": [
"index.d.ts"
"src/index.ts"
]
}
1 change: 1 addition & 0 deletions packages/kbn-ace/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.0.0",
"private": true,
"main": "./target/index.js",
"types": "./target/index.d.ts",
"license": "SSPL-1.0 OR Elastic License 2.0",
"scripts": {
"build": "node ./scripts/build.js",
Expand Down
6 changes: 4 additions & 2 deletions packages/kbn-ace/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"incremental": false,
"outDir": "./target",
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"sourceRoot": "../../../../packages/kbn-ace/src",
"types": [
"jest",
"node"
]
],
},
"include": [
"src/**/*"
Expand Down
11 changes: 5 additions & 6 deletions packages/kbn-analytics/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"declaration": true,
"emitDeclarationOnly": true,
"incremental": false,
"outDir": "./target/types",
"stripInternal": true,
"emitDeclarationOnly": true,
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"sourceRoot": "../../../../../packages/kbn-analytics/src",
"types": [
"jest",
"node"
]
},
"include": [
"src/**/*"
],
"exclude": [
"target"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import { relative, resolve } from 'path';
import { getConfigFromFiles } from './read_config';

const fixtureFile = (name: string) => resolve(__dirname, '..', '..', '__fixtures__', name);
const fixtureFile = (name: string) => resolve(__dirname, '..', '__fixtures__', name);

test('reads single yaml from file system and parses to json', () => {
const config = getConfigFromFiles([fixtureFile('config.yml')]);
Expand Down
15 changes: 11 additions & 4 deletions packages/kbn-apm-config-loader/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"declaration": true,
"incremental": false,
"outDir": "./target",
"stripInternal": false,
"declaration": true,
"declarationMap": true,
"types": ["jest", "node"]
"sourceMap": true,
"sourceRoot": "../../../../packages/kbn-apm-config-loader/src",
"types": [
"jest",
"node"
]
},
"include": ["./src/**/*.ts"],
"exclude": ["target"]
"include": [
"src/**/*.ts"
]
}
8 changes: 4 additions & 4 deletions packages/kbn-apm-utils/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"declaration": true,
"incremental": false,
"outDir": "./target",
"stripInternal": false,
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"sourceRoot": "../../../../packages/kbn-apm-utils/src",
"types": [
"node"
]
},
"include": [
"./src/**/*.ts"
],
"exclude": [
"target"
]
}
15 changes: 11 additions & 4 deletions packages/kbn-cli-dev-mode/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"declaration": true,
"incremental": false,
"outDir": "./target",
"declaration": true,
"declarationMap": true,
"types": ["jest", "node"]
"sourceMap": true,
"sourceRoot": "../../../../packages/kbn-cli-dev-mode/src",
"types": [
"jest",
"node"
]
},
"include": ["./src/**/*.ts"],
"exclude": ["target"]
"include": [
"./src/**/*.ts"
],
}
14 changes: 7 additions & 7 deletions packages/kbn-config-schema/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"declaration": true,
"declarationDir": "./target/types",
"incremental": false,
"outDir": "./target/out",
"declarationDir": "./target/types",
"stripInternal": true,
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"sourceRoot": "../../../../../packages/kbn-config-schema/src",
"types": [
"jest",
"node"
]
},
"include": [
"./types/joi.d.ts",
"./src/**/*.ts"
],
"exclude": [
"target"
"types/joi.d.ts",
"src/**/*.ts"
]
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/kbn-config/src/raw/read_config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import { relative, resolve } from 'path';
import { getConfigFromFiles } from './read_config';

const fixtureFile = (name: string) => resolve(`${__dirname}/../../__fixtures__/${name}`);
const fixtureFile = (name: string) => resolve(`${__dirname}/../__fixtures__/${name}`);

test('reads single yaml from file system and parses to json', () => {
const config = getConfigFromFiles([fixtureFile('config.yml')]);
Expand Down
Loading

0 comments on commit 50313f7

Please sign in to comment.