Skip to content

Commit c4ab832

Browse files
merge master
2 parents c1962a7 + b03bca5 commit c4ab832

30 files changed

+9715
-6671
lines changed

.github/workflows/node.js.yml

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@ name: Node.js CI
55

66
on:
77
push:
8-
branches: [ master ]
8+
branches: [master]
99
pull_request:
10-
branches: [ master ]
10+
branches: [master]
1111

1212
jobs:
1313
build:
14-
1514
runs-on: ubuntu-latest
1615

1716
strategy:
@@ -20,11 +19,11 @@ jobs:
2019
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
2120

2221
steps:
23-
- uses: actions/checkout@v2
24-
- name: Use Node.js ${{ matrix.node-version }}
25-
uses: actions/setup-node@v2
26-
with:
27-
node-version: ${{ matrix.node-version }}
28-
cache: 'npm'
29-
- run: npm install
30-
- run: npm test
22+
- uses: actions/checkout@v2
23+
- name: Use Node.js ${{ matrix.node-version }}
24+
uses: actions/setup-node@v2
25+
with:
26+
node-version: ${{ matrix.node-version }}
27+
cache: 'npm'
28+
- run: npm install
29+
- run: npm test

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ results
2121

2222
npm-debug.log
2323
node_modules
24+
.yarn
2425
# yarn.lock
2526
package-lock.json
2627

.npmignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
.travis.yml
66
appveyor.yml
77
Gruntfile.js
8-
tasks
9-
test
8+
/tasks
9+
/test
10+
/src

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
14
1+
16

.yarnrc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nodeLinker: node-modules

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
## Change Log
22

3+
### v0.49.23
4+
5+
- [#1320](https://github.com/opencomponents/oc/pull/1320) make npmignore applied only to root folders
6+
7+
### v0.49.22
8+
9+
- [#1319](https://github.com/opencomponents/oc/pull/1319) Check unverified packages after start/publishing
10+
11+
### v0.49.21
12+
13+
- [#1303](https://github.com/opencomponents/oc/pull/1303) add ability to retreieve environment variables from an env file
14+
- [#1312](https://github.com/opencomponents/oc/pull/1312) Upgrade project default Node.js version to 16
15+
- [#1317](https://github.com/opencomponents/oc/pull/1317) Bump loader-utils from 1.4.0 to 1.4.2
16+
17+
### v0.49.19
18+
19+
- [#1315](https://github.com/opencomponents/oc/pull/1315) include the entire console api in the production stub
20+
321
### v0.49.16
422

523
- [#1313](https://github.com/opencomponents/oc/pull/1313) remove some any types

package.json

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
{
22
"name": "oc",
3-
"version": "0.49.18",
3+
"version": "0.49.23",
44
"description": "A framework for developing and distributing html components",
55
"main": "./dist/index.js",
66
"types": "./dist/index.d.ts",
7-
"bin": {
8-
"oc": "./dist/oc-cli.js"
9-
},
7+
"bin": "./dist/oc-cli.js",
108
"scripts": {
119
"lint": "eslint src",
1210
"prebuild": "rimraf dist",
1311
"build": "npm run lint && tsc && node tasks/build.js",
1412
"git-stage-and-push": "node tasks/git-stage-and-push.js",
1513
"npm-publish": "node tasks/npm-publish.js",
16-
"publish-major": "npm run version-major && npm run test-silent && npm run git-stage-and-push && npm run npm-publish",
17-
"publish-minor": "npm run version-minor && npm run test-silent && npm run git-stage-and-push && npm run npm-publish",
18-
"publish-patch": "npm run version-patch && npm run test-silent && npm run git-stage-and-push && npm run npm-publish",
14+
"publish-major": "npm run test-silent && npm run version-major && node tasks/build.js && npm run git-stage-and-push && npm run npm-publish",
15+
"publish-minor": "npm run test-silent && npm run version-minor && node tasks/build.js && npm run git-stage-and-push && npm run npm-publish",
16+
"publish-patch": "npm run test-silent && npm run version-patch && node tasks/build.js && npm run git-stage-and-push && npm run npm-publish",
1917
"test": "npm run build && node tasks/mochaTest.js",
2018
"test-silent": "npm run build && node tasks/mochaTest.js --silent",
2119
"version-major": "node tasks/version.js --type=\"major\"",
@@ -43,45 +41,45 @@
4341
],
4442
"devDependencies": {
4543
"@types/accept-language-parser": "1.5.3",
46-
"@types/async": "3.2.15",
44+
"@types/async": "3.2.16",
4745
"@types/cross-spawn": "6.0.2",
4846
"@types/errorhandler": "1.5.0",
49-
"@types/express": "4.17.14",
47+
"@types/express": "4.17.15",
5048
"@types/fs-extra": "9.0.13",
5149
"@types/got": "^9.6.12",
5250
"@types/livereload": "0.9.2",
53-
"@types/lodash": "4.14.186",
51+
"@types/lodash": "4.14.191",
5452
"@types/morgan": "1.9.3",
5553
"@types/multer": "1.4.7",
56-
"@types/node": "18.8.4",
54+
"@types/node": "18.11.16",
5755
"@types/parse-author": "2.0.1",
5856
"@types/read": "0.0.29",
5957
"@types/response-time": "2.3.5",
60-
"@types/semver": "7.3.12",
58+
"@types/semver": "7.3.13",
6159
"@types/targz": "1.0.1",
62-
"@types/yargs": "17.0.13",
63-
"@typescript-eslint/eslint-plugin": "5.40.0",
64-
"@typescript-eslint/parser": "5.40.0",
65-
"chai": "4.3.6",
60+
"@types/yargs": "17.0.17",
61+
"@typescript-eslint/eslint-plugin": "5.46.1",
62+
"@typescript-eslint/parser": "5.46.1",
63+
"chai": "4.3.7",
6664
"chalk": "4.1.2",
67-
"eslint": "8.25.0",
65+
"eslint": "8.30.0",
6866
"eslint-config-prettier": "8.5.0",
6967
"eslint-plugin-prettier": "4.2.1",
7068
"glob": "7.2.0",
71-
"husky": "7.0.4",
69+
"husky": "8.0.2",
7270
"injectr": "0.5.1",
7371
"minimist": "1.2.7",
7472
"mocha": "9.1.3",
7573
"node-emoji": "1.11.0",
7674
"p-limit": "^3.1.0",
77-
"prettier": "2.7.1",
75+
"prettier": "2.8.1",
7876
"rimraf": "3.0.2",
7977
"semver-sort": "1.0.0",
8078
"simple-git": "2.48.0",
8179
"sinon": "12.0.1",
8280
"ts-node": "10.9.1",
8381
"type-fest": "2.8.0",
84-
"typescript": "4.8.4"
82+
"typescript": "4.9.4"
8583
},
8684
"dependencies": {
8785
"accept-language-parser": "1.5.0",
@@ -92,10 +90,11 @@
9290
"colors": "1.4.0",
9391
"cross-spawn": "7.0.3",
9492
"dependency-graph": "0.11.0",
93+
"dotenv": "16.0.3",
9594
"errorhandler": "1.5.1",
9695
"express": "4.18.2",
9796
"form-data": "4.0.0",
98-
"fs-extra": "10.1.0",
97+
"fs-extra": "11.1.0",
9998
"getport": "0.1.0",
10099
"got": "11.8.5",
101100
"livereload": "0.9.3",
@@ -127,6 +126,6 @@
127126
"targz": "1.0.1",
128127
"try-require": "1.2.1",
129128
"universalify": "^2.0.0",
130-
"yargs": "17.6.0"
129+
"yargs": "17.6.2"
131130
}
132131
}

src/components/oc-client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "oc-client",
33
"description": "The OpenComponents client-side javascript client",
4-
"version": "0.49.18",
4+
"version": "0.49.23",
55
"repository": "https://github.com/opencomponents/oc/tree/master/components/oc-client",
66
"author": "Matteo Figus <[email protected]>",
77
"oc": {

src/registry/domain/components-cache/components-list.ts

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import semver from 'semver';
22
import pLimit from 'p-limit';
33
import getUnixUTCTimestamp from 'oc-get-unix-utc-timestamp';
4-
import { ComponentsList, Config } from '../../../types';
54
import { StorageAdapter } from 'oc-storage-adapters-utils';
5+
import eventsHandler from '../events-handler';
6+
import { ComponentsList, Config } from '../../../types';
67

78
export default function componentsList(conf: Config, cdn: StorageAdapter) {
89
const filePath = (): string =>
@@ -11,17 +12,64 @@ export default function componentsList(conf: Config, cdn: StorageAdapter) {
1112
const componentsList = {
1213
getFromJson: (): Promise<ComponentsList> => cdn.getJson(filePath(), true),
1314

14-
getFromDirectories: async (): Promise<ComponentsList> => {
15+
getFromDirectories: async (
16+
jsonList: ComponentsList | null
17+
): Promise<ComponentsList> => {
1518
const componentsInfo: Record<string, string[]> = {};
1619

20+
const validateComponentVersion = (
21+
componentName: string,
22+
componentVersion: string
23+
) => {
24+
return cdn
25+
.getJson(
26+
// Check integrity of the package by checking existence of package.json
27+
// OC will upload always the package.json last when publishing
28+
`${conf.storage.options.componentsDir}/${componentName}/${componentVersion}/package.json`
29+
)
30+
.then(() => true)
31+
.catch(() => false);
32+
};
33+
1734
const getVersionsForComponent = async (
1835
componentName: string
1936
): Promise<string[]> => {
20-
const versions = await cdn.listSubDirectories(
37+
const allVersions = await cdn.listSubDirectories(
2138
`${conf.storage.options.componentsDir}/${componentName}`
2239
);
40+
const unCheckedVersions = allVersions.filter(
41+
version => !jsonList?.components[componentName]?.includes(version)
42+
);
43+
const limit = pLimit(cdn.maxConcurrentRequests);
44+
const invalidVersions = (
45+
await Promise.all(
46+
unCheckedVersions.map(unCheckedVersion =>
47+
limit(async () => {
48+
const isValid = await validateComponentVersion(
49+
componentName,
50+
unCheckedVersion
51+
);
52+
53+
return isValid ? null : unCheckedVersion;
54+
})
55+
)
56+
)
57+
).filter((x): x is string => typeof x === 'string');
58+
59+
if (invalidVersions.length > 0) {
60+
eventsHandler.fire('error', {
61+
code: 'corrupted_version',
62+
message: `Couldn't validate the integrity of the component ${componentName} on the following versions: ${invalidVersions.join(
63+
', '
64+
)}.`
65+
});
66+
}
67+
68+
const validVersions = allVersions.filter(
69+
version => !invalidVersions.includes(version)
70+
);
2371

24-
return versions.sort(semver.compare);
72+
return validVersions.sort(semver.compare);
2573
};
2674

2775
try {
@@ -55,8 +103,8 @@ export default function componentsList(conf: Config, cdn: StorageAdapter) {
55103
}
56104
},
57105

58-
async refresh(): Promise<ComponentsList> {
59-
const components = await componentsList.getFromDirectories();
106+
async refresh(cachedList: ComponentsList): Promise<ComponentsList> {
107+
const components = await componentsList.getFromDirectories(cachedList);
60108
await componentsList.save(components);
61109

62110
return components;

src/registry/domain/components-cache/index.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ import getComponentsList from './components-list';
33
import eventsHandler from '../events-handler';
44
import getUnixUTCTimestamp from 'oc-get-unix-utc-timestamp';
55
import { ComponentsList, Config } from '../../../types';
6-
import { StorageAdapter } from 'oc-storage-adapters-utils';
6+
import { StorageAdapter, strings } from 'oc-storage-adapters-utils';
77

88
export default function componentsCache(conf: Config, cdn: StorageAdapter) {
99
let cachedComponentsList: ComponentsList;
1010
let refreshLoop: NodeJS.Timeout;
1111

1212
const componentsList = getComponentsList(conf, cdn);
1313

14-
const poll = () =>
15-
setTimeout(async () => {
14+
const poll = () => {
15+
return setTimeout(async () => {
1616
try {
1717
const data = await componentsList.getFromJson();
1818

@@ -29,6 +29,7 @@ export default function componentsCache(conf: Config, cdn: StorageAdapter) {
2929
}
3030
refreshLoop = poll();
3131
}, conf.pollingInterval * 1000);
32+
};
3233

3334
const cacheDataAndStartPolling = (data: ComponentsList) => {
3435
cachedComponentsList = data;
@@ -55,12 +56,15 @@ export default function componentsCache(conf: Config, cdn: StorageAdapter) {
5556
},
5657

5758
async load(): Promise<ComponentsList> {
59+
const jsonComponents = await componentsList.getFromJson().catch(err => {
60+
if (err?.code === strings.errors.STORAGE.FILE_NOT_FOUND_CODE)
61+
return null;
62+
63+
return Promise.reject(err);
64+
});
5865
const dirComponents = await componentsList
59-
.getFromDirectories()
66+
.getFromDirectories(jsonComponents)
6067
.catch(err => throwError('components_list_get', err));
61-
const jsonComponents = await componentsList
62-
.getFromJson()
63-
.catch(() => null);
6468

6569
if (
6670
!jsonComponents ||
@@ -78,7 +82,8 @@ export default function componentsCache(conf: Config, cdn: StorageAdapter) {
7882
async refresh(): Promise<ComponentsList> {
7983
clearTimeout(refreshLoop);
8084
try {
81-
const components = await componentsList.refresh();
85+
// Passing components that we know are fine, so it doesn't refresh invalid components
86+
const components = await componentsList.refresh(cachedComponentsList);
8287
cacheDataAndStartPolling(components);
8388

8489
return components;

0 commit comments

Comments
 (0)