Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(NA): enable preserve symlinks for ts without breaking packages development #95433

Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
deb459d
chore(NA): move elastic-datemath into a ts package
mistic Mar 22, 2021
60a73d4
chore(NA): finish elastic-datemath
mistic Mar 23, 2021
b43a43a
chore(NA): finish elastic-datemath
mistic Mar 23, 2021
cb74fba
chore(NA): source folder for elastic-datemath
mistic Mar 23, 2021
df416ef
chore(NA): add source-maps ace, analytics, apm-config-loader and apm-…
mistic Mar 23, 2021
cca00ae
chore(NA): add sourcemaps to packages on typescript
mistic Mar 23, 2021
4a3f3c7
chore(NA): move test fixtures within source
mistic Mar 23, 2021
36223d7
chore(NA): correct exclusions on packages
mistic Mar 24, 2021
4cd98ae
chore(NA): correct package.json on all packages
mistic Mar 24, 2021
1951698
chore(NA): correct package.json on all packages
mistic Mar 24, 2021
76bacc3
chore(NA): complete kbn pm
mistic Mar 24, 2021
1c3fcc9
Merge remote-tracking branch 'upstream/master' into enable-preserve-s…
mistic Mar 25, 2021
2801517
Merge remote-tracking branch 'upstream/master' into enable-preserve-s…
mistic Mar 25, 2021
fe545a7
chore(NA): default export on elastic-datemath
mistic Mar 25, 2021
1a7df27
chore(NA): include logs on kbn-logging
mistic Mar 25, 2021
eab1c76
chore(NA): update bundle ref module to last code used in the webpack …
mistic Mar 25, 2021
88bb993
chore(NA): update bundle ref module to last code used in the webpack …
mistic Mar 25, 2021
9268491
chore(NA): remove override method for exportsArgument
mistic Mar 26, 2021
f30edf0
fix(NA): typechecking problems by use @internal at javascript import …
mistic Mar 29, 2021
9521130
fix(NA): typescript projects check
mistic Mar 29, 2021
3c11f41
fix(NA): run optimizer integration tests from source
mistic Mar 30, 2021
9419249
Merge remote-tracking branch 'upstream/master' into enable-preserve-s…
mistic Mar 30, 2021
fad2630
chore(NA): fix usage from target for kbn optimizer
mistic Mar 30, 2021
1d42309
chore(NA): path on tsconfig
mistic Mar 30, 2021
b023711
Merge remote-tracking branch 'upstream/master' into enable-preserve-s…
mistic Mar 30, 2021
0376665
chore(NA): move tsignore into ts-expect-error
mistic Mar 30, 2021
89ec37e
Merge remote-tracking branch 'upstream/master' into enable-preserve-s…
mistic Mar 30, 2021
2ae87d6
chore(NA): include souce maps on kbn cli dev
mistic Mar 30, 2021
1639661
chore(NA): include souce maps on kbn-crypto, kbn-server-http-tools an…
mistic Mar 30, 2021
f00f4f0
chore(NA): add issue links into the ts-expect-error comments
mistic Mar 30, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
}
}
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,
tylersmalley marked this conversation as resolved.
Show resolved Hide resolved
"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
18 changes: 14 additions & 4 deletions packages/kbn-apm-config-loader/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
{
"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"
],
"exclude": [
"**/**/*.test.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"
]
}
9 changes: 6 additions & 3 deletions packages/kbn-config-schema/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
{
"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"
Expand All @@ -16,6 +19,6 @@
"./src/**/*.ts"
],
"exclude": [
"target"
"**/**/*.test.ts"
]
}
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
23 changes: 19 additions & 4 deletions packages/kbn-config/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
{
"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-config/src",
"types": [
"jest",
"node"
]
},
"include": ["./src/**/*.ts"],
"exclude": ["target"]
"include": [
"./src/**/*.ts"
],
"exclude": [
"**/__fixtures__/**/*",
"**/__mocks__/**/*",
"**/**/*.mock.ts",
"**/**/*.mocks.ts",
"**/**/*.test.ts",
"**/**/*.test.mocks.ts"
]
}
Loading