Skip to content

Commit

Permalink
Merge pull request #4164 from SherpasGroup/upgrade-to-spfx-1.20
Browse files Browse the repository at this point in the history
Upgrade to SPFx 1.20.0
  • Loading branch information
wobba authored Dec 16, 2024
2 parents 87047b8 + b54a0be commit af2ec36
Show file tree
Hide file tree
Showing 21 changed files with 25,175 additions and 27,400 deletions.
33 changes: 0 additions & 33 deletions search-parts/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,39 +19,6 @@ module.exports = {
'@rushstack/security/no-unsafe-regexp': 0,
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
'@typescript-eslint/adjacent-overload-signatures': 1,
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
//
// CONFIGURATION: By default, these are banned: String, Boolean, Number, Object, Symbol
'@typescript-eslint/ban-types': [
1,
{
'extendDefaults': false,
'types': {
'String': {
'message': 'Use \'string\' instead',
'fixWith': 'string'
},
'Boolean': {
'message': 'Use \'boolean\' instead',
'fixWith': 'boolean'
},
'Number': {
'message': 'Use \'number\' instead',
'fixWith': 'number'
},
'Object': {
'message': 'Use \'object\' instead, or else define a proper TypeScript type:'
},
'Symbol': {
'message': 'Use \'symbol\' instead',
'fixWith': 'symbol'
},
'Function': {
'message': 'The \'Function\' type accepts any function-like value.\nIt provides no type safety when calling the function, which can be a common source of bugs.\nIt also accepts things like class declarations, which will throw at runtime as they will not be called with \'new\'.\nIf you are expecting the function to accept certain arguments, you should explicitly define the function shape.'
}
}
}
],
// RATIONALE: Code is more readable when the type of every variable is immediately obvious.
// Even if the compiler may be able to infer a type, this inference will be unavailable
// to a person who is reviewing a GitHub diff. This rule makes writing code harder,
Expand Down
4 changes: 2 additions & 2 deletions search-parts/.yo-rc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"plusBeta": false,
"isCreatingSolution": true,
"environment": "spo",
"version": "1.18.2",
"version": "1.20.0",
"solutionName": "modern-pnp-modern-search-web-parts",
"libraryName": "modern-pnp-modern-search-web-parts",
"libraryId": "8aa14115-d64a-4545-b215-ee8fb8d82e59",
Expand All @@ -14,7 +14,7 @@
"skipFeatureDeployment": true,
"nodeVersion": "16.20.0",
"sdkVersions": {
"@microsoft/teams-js": "2.12.0",
"@microsoft/teams-js": "2.24.0",
"@microsoft/microsoft-graph-client": "3.0.2"
}
}
Expand Down
77 changes: 47 additions & 30 deletions search-parts/fast-serve/webpack.extend.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,24 @@
*/

const webpack = require("webpack");
const { IgnorePlugin } = require('webpack');
const { ProvidePlugin } = require('webpack');

// you can add your project related webpack configuration here, it will be merged using webpack-merge module
// i.e. plugins: [new webpack.Plugin()]
const webpackConfig = {
node: {
fs: "empty"
},
resolve: {
alias: { handlebars: 'handlebars/dist/handlebars.min.js' }
alias: {
handlebars: 'handlebars/dist/handlebars.min.js',
process: 'process/browser',
},
fallback: {
"path": require.resolve("path-browserify"),
"util": require.resolve("util/"),
"url": require.resolve("url/"),
"querystring": require.resolve("querystring-es3"),
"fs": false
}
},
module: {
rules: [{
Expand All @@ -33,31 +42,33 @@ const webpackConfig = {
]
}
}
}, {
test: /utils\.js$/,
loader: "unlazy-loader",
include: [
/node_modules/,
]
},
{
test: /index.js$/,
loader: 'string-replace-loader',
include: [
/handlebars-helpers/,
],
options: {
search: '(logging|markdown): require.*?,',
replace: '',
flags: 'g'
}
}, {
// Skip HoverReactionsBar from spfx controls as it's not used and is bundles
test: /index\.js$/,
include: [/spfx-controls-react[/\\]lib[/\\]controls[/\\]HoverReactionsBar/],
loader: 'ignore-loader',
}
]
},
{
test: /utils\.js$/,
loader: "unlazy-loader",
include: [
/node_modules/,
]
},
{
test: /index.js$/,
loader: 'string-replace-loader',
include: [
/handlebars-helpers/,
],
options: {
search: '(logging|markdown): require.*?,',
replace: '',
flags: 'g'
}
},
{
// Skip HoverReactionsBar from spfx controls as it's not used and is bundles
test: /index\.js$/,
include: [/spfx-controls-react[/\\]lib[/\\]controls[/\\]HoverReactionsBar/],
loader: 'ignore-loader',
}
]
},
optimization: {
splitChunks: {
Expand All @@ -67,7 +78,13 @@ const webpackConfig = {
}
},
plugins: [
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)
new IgnorePlugin({
resourceRegExp: /^\.\/locale$/, // Example: Ignore all locale files
contextRegExp: /moment$/ // Example: Ignore locale files in moment package
}),
new ProvidePlugin({
process: 'process/browser'
}),
]
}

Expand Down
129 changes: 73 additions & 56 deletions search-parts/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ const build = require('@microsoft/sp-build-web');
const bundleAnalyzer = require('webpack-bundle-analyzer');
const log = require('fancy-log');
const fs = require('fs');
const semver = require('semver');
const { DefinePlugin } = require('webpack');
const { IgnorePlugin } = require('webpack');
const { ProvidePlugin } = require('webpack');

const readJson = (path, cb) => {
fs.readFile(require.resolve(path), (err, data) => {
Expand Down Expand Up @@ -43,11 +47,18 @@ const envCheck = build.subTask('environmentCheck', (gulp, config, done) => {
build.configureWebpack.mergeConfig({
additionalConfiguration: (generatedConfiguration) => {

generatedConfiguration.resolve.alias = { handlebars: 'handlebars/dist/handlebars.min.js' };
generatedConfiguration.resolve.alias = {
handlebars: 'handlebars/dist/handlebars.min.js',
process: "process/browser",
};

generatedConfiguration.node = {
fs: 'empty'
}
generatedConfiguration.resolve.fallback = {
"path": require.resolve("path-browserify"),
"util": require.resolve("util/"),
"url": require.resolve("url/"),
"querystring": require.resolve("querystring-es3"),
"fs": false
};

generatedConfiguration.module.rules.push({
test: /\.js$/,
Expand Down Expand Up @@ -95,7 +106,13 @@ const envCheck = build.subTask('environmentCheck', (gulp, config, done) => {

// pack each moment.js locale individually to optimize bundle
generatedConfiguration.plugins.push(
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)
new IgnorePlugin({
resourceRegExp: /^\.\/locale$/, // Example: Ignore all locale files
contextRegExp: /moment$/ // Example: Ignore locale files in moment package
}),
new ProvidePlugin({
process: 'process/browser'
}),
);

if (config.production) {
Expand Down Expand Up @@ -156,59 +173,59 @@ const findFilesByExt = (base, ext, files, result) => {

gulp.task('update-version', async () => {

// List all manifest files
const manifestFiles = findFilesByExt('./src', 'manifest.json');

const semver = require('semver')
const versionArgIdx = process.argv.indexOf('--value');
const newVersionNumber = semver.valid(process.argv[versionArgIdx + 1]);

if (versionArgIdx !== -1 && newVersionNumber) {

// Update version in the package-solution
const pkgSolutionFilePath = './config/package-solution.json';

readJson(pkgSolutionFilePath, (err, pkgSolution) => {
log.info('Old package-solution.json version:\t' + pkgSolution.solution.version);
const pkgVersion = `${semver.major(newVersionNumber)}.${semver.minor(newVersionNumber)}.${semver.patch(newVersionNumber)}.0`;
pkgSolution.solution.version = pkgVersion
log.info('New package-solution.json version:\t' + pkgVersion);
fs.writeFile(pkgSolutionFilePath, JSON.stringify(pkgSolution, null, 4), (error) => { });
});

// Updated version in Web Part manifests
manifestFiles.forEach((manifestFile) => {
readJson(`./${manifestFile}`, (err, manifest) => {

log.info(`Updating manifest file: "./${manifestFile}"`);

log.info('Old manifestFile version:\t' + manifest.version);
const wpVersion = `${semver.major(newVersionNumber)}.${semver.minor(newVersionNumber)}.${semver.patch(newVersionNumber)}`;
manifest.version = wpVersion;
log.info('New manifestFile version:\t' + wpVersion);
fs.writeFile(manifestFile, JSON.stringify(manifest, null, 4), (error) => { });
});
});
} else {
log.error(`The provided version ${process.argv[versionArgIdx + 1]} is not a valid SemVer version`);
}
// List all manifest files
const manifestFiles = findFilesByExt('./src', 'manifest.json');

const semver = require('semver')
const versionArgIdx = process.argv.indexOf('--value');
const newVersionNumber = semver.valid(process.argv[versionArgIdx + 1]);

if (versionArgIdx !== -1 && newVersionNumber) {

// Update version in the package-solution
const pkgSolutionFilePath = './config/package-solution.json';

readJson(pkgSolutionFilePath, (err, pkgSolution) => {
log.info('Old package-solution.json version:\t' + pkgSolution.solution.version);
const pkgVersion = `${semver.major(newVersionNumber)}.${semver.minor(newVersionNumber)}.${semver.patch(newVersionNumber)}.0`;
pkgSolution.solution.version = pkgVersion
log.info('New package-solution.json version:\t' + pkgVersion);
fs.writeFile(pkgSolutionFilePath, JSON.stringify(pkgSolution, null, 4), (error) => { });
});

// Updated version in Web Part manifests
manifestFiles.forEach((manifestFile) => {
readJson(`./${manifestFile}`, (err, manifest) => {

log.info(`Updating manifest file: "./${manifestFile}"`);

log.info('Old manifestFile version:\t' + manifest.version);
const wpVersion = `${semver.major(newVersionNumber)}.${semver.minor(newVersionNumber)}.${semver.patch(newVersionNumber)}`;
manifest.version = wpVersion;
log.info('New manifestFile version:\t' + wpVersion);
fs.writeFile(manifestFile, JSON.stringify(manifest, null, 4), (error) => { });
});
});
} else {
log.error(`The provided version ${process.argv[versionArgIdx + 1]} is not a valid SemVer version`);
}
});

gulp.task('update-package-name', async () => {

const pkgSolutionFilePath = './config/package-solution.json';

const fileNameArg = process.argv.indexOf('--name');
const fileName = process.argv[fileNameArg + 1];

if (fileNameArg !== -1 && fileName) {
readJson(pkgSolutionFilePath, (err, pkgSolution) => {
const currentPackageName = path.basename(pkgSolution.paths.zippedPackage, '.sppkg');
log.info(`Rename ${currentPackageName}.sppkg to ${fileName}.sppkg`);
pkgSolution.paths.zippedPackage = pkgSolution.paths.zippedPackage.replace(path.basename(pkgSolution.paths.zippedPackage, '.sppkg'), fileName);
fs.writeFile(pkgSolutionFilePath, JSON.stringify(pkgSolution, null, 4), (error) => { });
});
} else {
log.error(`Error: wrong parameters`);
}
const pkgSolutionFilePath = './config/package-solution.json';

const fileNameArg = process.argv.indexOf('--name');
const fileName = process.argv[fileNameArg + 1];

if (fileNameArg !== -1 && fileName) {
readJson(pkgSolutionFilePath, (err, pkgSolution) => {
const currentPackageName = path.basename(pkgSolution.paths.zippedPackage, '.sppkg');
log.info(`Rename ${currentPackageName}.sppkg to ${fileName}.sppkg`);
pkgSolution.paths.zippedPackage = pkgSolution.paths.zippedPackage.replace(path.basename(pkgSolution.paths.zippedPackage, '.sppkg'), fileName);
fs.writeFile(pkgSolutionFilePath, JSON.stringify(pkgSolution, null, 4), (error) => { });
});
} else {
log.error(`Error: wrong parameters`);
}
});
Loading

0 comments on commit af2ec36

Please sign in to comment.