Socket
Socket
Sign inDemoInstall

@talend/scripts-config-cdn

Package Overview
Dependencies
Maintainers
1
Versions
130
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@talend/scripts-config-cdn - npm Package Compare versions

Comparing version 9.10.1 to 9.10.2

__mocks__/fs.js

6

CHANGELOG.md
# CHANGELOG
## 9.10.2
### Patch Changes
- fcccad6: fix(config-cdn): find package for copy takes scope into account
## 9.10.1

@@ -4,0 +10,0 @@

84

find.js

@@ -12,3 +12,3 @@ const fs = require('fs');

}
if(path.resolve(cwd, '..') !== cwd) {
if (path.resolve(cwd, '..') !== cwd) {
cwd = path.resolve(cwd, '..');

@@ -36,33 +36,61 @@ } else {

function findPackages(scope, fname, startPath, buff = []) {
const root = findRootNodeModule(startPath);
return buff.concat(
fs
.readdirSync(root, { withFileTypes: true })
.filter(f => f.isDirectory())
.reduce((acc, f) => {
if (f.name === '.bin') {
return acc;
function findPackagesFromScopeFolder(scope, name, scopeFolderPath) {
const isWantedScope = scopeFolderPath.endsWith(`${path.sep}${scope}`);
return fs
.readdirSync(scopeFolderPath, { withFileTypes: true })
.filter(f => f.isDirectory())
.reduce((accu, subFolder) => {
const subFolderPath = path.join(scopeFolderPath, subFolder.name);
if (isWantedScope && subFolder.name === name) {
// the scope and package name are the ones we look for
// just add the path to the found list
return accu.concat(subFolderPath);
} else {
// the scope or package name is not the one we look for
// if there is a nested node modules folder, we dive into it for the search
const nestedNodeModulesPath = path.join(subFolderPath, 'node_modules');
if (fs.existsSync(nestedNodeModulesPath)) {
return accu.concat(
findPackagesFromNonScopeFolder(scope, name, nestedNodeModulesPath, []),
);
}
if (f.name.startsWith('@')) {
const result = findPackages(scope, fname, `${root}/${f.name}`, []);
if (result.length > 0) {
return acc.concat(result);
}
} else {
if (f.name === fname) {
return acc.concat(`${root}/${f.name}`);
}
if (fs.existsSync(`${root}/${f.name}/node_modules`)) {
const result = findPackages(scope, fname, `${root}/${f.name}/node_modules`, []);
if (result.length > 0) {
return acc.concat(result);
}
}
}
return accu;
}, []);
}
function findPackagesFromNonScopeFolder(scope, name, nonScopeFolderPath) {
return fs
.readdirSync(nonScopeFolderPath, { withFileTypes: true })
.filter(f => f.isDirectory())
.reduce((accu, subFolder) => {
if (subFolder.name === '.bin') {
return accu;
}
if (subFolder.name.startsWith('@')) {
// for scope folders, we need a special treatment to avoid getting scoped packages when we don't want a scoped one.
// ex: search for `classnames`, we don't want to find `@types/classnames` in the result
return accu.concat(
findPackagesFromScopeFolder(scope, name, path.join(nonScopeFolderPath, subFolder.name)),
);
} else if (!scope && subFolder.name === name) {
// we want a NON scoped package, we are in a non scoped folder, and the names match
return accu.concat(path.join(nonScopeFolderPath, subFolder.name));
} else {
const nestedNodeModulesPath = path.join(nonScopeFolderPath, subFolder.name, 'node_modules');
if (fs.existsSync(nestedNodeModulesPath)) {
return accu.concat(findPackagesFromNonScopeFolder(scope, name, nestedNodeModulesPath));
}
return acc;
}, []),
);
}
return accu;
}, []);
}
function findPackages(scope, name, startPath, buff = []) {
// root = startPath if provided
// else if takes the first node_modules from cwd to the top
const root = findRootNodeModule(startPath);
return buff.concat(findPackagesFromNonScopeFolder(scope, name, root));
}
module.exports = {

@@ -69,0 +97,0 @@ findRootNodeModule,

const path = require('path');
const find = require('./find');
const { findPackages } = require('./find');
describe('find', () => {
it('should find recursively libs', () => {
const results = find('@babel', 'core', path.resolve(__dirname, '../../node_modules'));
expect(Array.isArray(results)).toBe(true);
expect(results.length > 0).toBe(true);
jest.mock('fs');
describe('findPackages', () => {
const MOCK_FILE_INFO = {
'/node_modules/classnames/index.js': 'console.log("classnames");',
'/node_modules/react/index.js': 'console.log("react");',
'/node_modules/@types/classnames/index.js': 'console.log("@types/classnames");',
'/node_modules/@talend/react-components/index.js': 'console.log("@talend/react-components");',
'/node_modules/@talend/react-components/node_modules/react/index.js': 'console.log("react");',
'/node_modules/@talend/react-containers/index.js': 'console.log("@talend/react-containers");',
};
beforeEach(() => {
// Set up some mocked out file info before each test
require('fs').__setMockFiles(MOCK_FILE_INFO);
});
test('should find root and nested package', () => {
// when
const result = findPackages('', 'react', '/node_modules');
// then
expect(result.length).toBe(2);
expect(result[0]).toBe('/node_modules/react');
expect(result[1]).toBe('/node_modules/@talend/react-components/node_modules/react');
});
test('should find non scoped package', () => {
// when
const result = findPackages('', 'classnames', '/node_modules');
// then
expect(result.length).toBe(1);
expect(result[0]).toBe('/node_modules/classnames');
});
test('should find scoped package', () => {
// when
const result = findPackages('@types', 'classnames', '/node_modules');
// then
expect(result.length).toBe(1);
expect(result[0]).toBe('/node_modules/@types/classnames');
});
});
{
"name": "@talend/scripts-config-cdn",
"version": "9.10.1",
"version": "9.10.2",
"description": "Provide a simple API to inject CDN config into existing webpack configuration",
"main": "cdn.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "jest"
},

@@ -9,0 +9,0 @@ "author": "Talend Frontend <frontend@talend.com> (http://www.talend.com)",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc