From 8d0bb70aecbb102efbe1800ef6cc3625c74c59c4 Mon Sep 17 00:00:00 2001 From: Joel Uong Date: Mon, 23 Dec 2024 08:45:18 -0600 Subject: [PATCH] add modified rollup config --- listFiles.js | 40 +++++++++++++++++++++++++++++++++++++++ package.json | 5 +++-- rollup.config.js | 49 +++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 85 insertions(+), 9 deletions(-) create mode 100644 listFiles.js diff --git a/listFiles.js b/listFiles.js new file mode 100644 index 00000000..aa3de9e4 --- /dev/null +++ b/listFiles.js @@ -0,0 +1,40 @@ +const fs = require('fs'); +const path = require('path'); + +/** + * Recursively collects all file paths in a directory. + * @param {string} dir - The directory to scan. + * @param {string} baseDir - The base directory for relative paths. + * @param {Array} fileList - Array to collect file paths. + * @returns {Array} The list of file paths. + */ +function getAllFiles(dir, baseDir = dir, fileList = []) { + const files = fs.readdirSync(dir); + + files.forEach((file) => { + const filePath = path.join(dir, file); + const stats = fs.statSync(filePath); + + if (stats.isDirectory()) { + getAllFiles(filePath, baseDir, fileList); // Recurse into subdirectory + } else { + fileList.push('"src/lib/' + path.relative(baseDir, filePath) + '",'); // Store relative path + } + }); + + return fileList; +} + +// Usage +const targetDir = process.argv[2]; // Directory passed as argument +if (!targetDir) { + console.error('Please provide a directory path.'); + process.exit(1); +} + +try { + const relativeFilePaths = getAllFiles(targetDir); + relativeFilePaths.forEach((filePath) => console.log(filePath)); +} catch (error) { + console.error(`Error reading directory: ${error.message}`); +} diff --git a/package.json b/package.json index 1db6b9b2..1420ce95 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "commerce-sdk-isomorphic", "version": "3.1.1", "private": false, + "sideEffects": false, "description": "Salesforce Commerce SDK Isomorphic", "bugs": { "url": "https://github.com/SalesforceCommerceCloud/commerce-sdk-isomorphic/issues" @@ -11,7 +12,7 @@ "url": "git+https://github.com/SalesforceCommerceCloud/commerce-sdk-isomorphic.git" }, "license": "BSD-3-Clause", - "main": "lib/index.cjs.js", + "main": "lib/index.js", "module": "lib/index.esm.js", "style": "lib/default.css", "files": [ @@ -122,7 +123,7 @@ "@typescript-eslint/eslint-plugin": "^4.33.0", "@typescript-eslint/parser": "^4.33.0", "autoprefixer": "9.8.8", - "bundlesize": "^0.18.1", + "bundlesize": "^0.18.2", "depcheck": "^1.4.3", "dotenv": "^16.0.3", "eslint": "^7.32.0", diff --git a/rollup.config.js b/rollup.config.js index d4b5312e..1d9dd889 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -20,12 +20,42 @@ import pkg from './package.json'; const extensions = ['.js', '.jsx', '.ts', '.tsx']; +const inputs = [ + "src/lib/clientConfig.ts", + "src/lib/config.ts", + "src/lib/helpers/customApi.ts", + "src/lib/helpers/environment.ts", + "src/lib/helpers/fetchHelper.ts", + "src/lib/helpers/index.ts", + "src/lib/helpers/slasHelper.ts", + "src/lib/helpers/types.ts", + "src/lib/index.ts", + "src/lib/responseError.ts", + "src/lib/shopperBaskets.ts", + "src/lib/shopperContexts.ts", + "src/lib/shopperCustomers.ts", + "src/lib/shopperDiscoverySearch.ts", + "src/lib/shopperExperience.ts", + "src/lib/shopperGiftCertificates.ts", + "src/lib/shopperLogin.ts", + "src/lib/shopperOrders.ts", + "src/lib/shopperProducts.ts", + "src/lib/shopperPromotions.ts", + "src/lib/shopperSearch.ts", + "src/lib/shopperSeo.ts", + "src/lib/shopperStores.ts", + "src/lib/templateUrl.ts", + "src/lib/version.ts", +] + const outputs = [ +// { +// dir: 'temp/umd', +// file: process.env.REACT_APP_PKG_MAIN || pkg.main, +// format: 'umd', +// }, { - file: process.env.REACT_APP_PKG_MAIN || pkg.main, - format: 'umd', - }, - { + dir: 'lib', file: process.env.REACT_APP_PKG_MODULE || pkg.module, format: 'es', }, @@ -39,10 +69,12 @@ const postcssPlugins = [ autoprefixer(), ]; -const config = outputs.map(({file, format}) => ({ - input: 'src/lib/index.ts', +const config = outputs.map(({dir, file, format}) => ({ +// input: 'src/lib/index.ts', + input: inputs, output: { - file, + // file, + dir, format, name: 'CommerceSdk', globals: { @@ -87,6 +119,9 @@ const config = outputs.map(({file, format}) => ({ terser(), filesize(), ], + treeshake: { + moduleSideEffects: false, // Ignore side effects + }, })); export default config;