Implemented flag to disable localization loader (#477)

* Updated webpack-plugin

* Updated changelog

* Fixed bug with broken imports

* Fixed rootPath for all systems

* Updated path to all loaders to support multi system

* Changed way to import loaders

* Updated pipeline

* Removed tests from release

* Fixed install-cert command

* Fixed regex to find api version

* Raised node.js version in pipeline

* Implemented flag to disable loc loader

* Removed test

* Updated changelog

* Fixed tests

---------

Co-authored-by: AleksSavelev <v-asavelev@microsoft.com>
This commit is contained in:
Aleksandr Savelev 2023-08-21 20:06:48 +02:00 коммит произвёл GitHub
Родитель 20d25d720f
Коммит 3151ab455a
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
9 изменённых файлов: 39 добавлений и 25 удалений

Просмотреть файл

@ -4,9 +4,13 @@ This page contains information about changes to the PowerBI Visual Tools (pbiviz
## 5.1.0
* New flag `--skip-api` to skip verifying api version. It might produce different errors in visual, so use it only in some specific cases (ex. installing something during the build process brakes packages managed by monorepo managers).
* New flag `--all-locales` to disable optimization using localization loader. It's recommended not to use this flag because all locales take a huge amount of package size. If you need just a few of them follow [this guide](https://learn.microsoft.com/en-us/power-bi/developer/visuals/localization?tabs=English#step-5---add-a-resources-file-for-each-language). In this case, only declared in stringResources locales will be added to your visual package.
## 5.0.3
* Now option `--install-cert` is command. The new usage is `pbiviz install-cert` **⚠**
## 5.0.3
* Now option `--install-cert` is command. New usage is `pbiviz install-cert`
* Fixed bug with the incorrect detection of the installed API version
## 5.0.2

Просмотреть файл

@ -75,6 +75,7 @@ pbiviz
.option('-d, --drop', 'Drop outputs into output folder')
.option('--no-stats', "Doesn't generate statistics files")
.option('--skip-api', "Skips powerbi-visuals-api verifying")
.option('-l, --all-locales', "Keeps all locale files in the package. By default only used inside stringResources folder locales are included.")
.action(async (options) => {
CommandManager.start(options, rootPath);
});
@ -87,6 +88,7 @@ pbiviz
.option('--no-minify', "Doesn't minify the js in the package (useful for debugging)")
.option('--no-stats', "Doesn't generate statistics files")
.option('--skip-api', "Skips powerbi-visuals-api verifying")
.option('-l, --all-locales', "Keeps all locale files in the package. By default only used inside stringResources folder locales are included.")
.addOption(new Option('-c, --compression <compressionLevel>', "Enables compression of visual package")
.choices(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'])
.default('6')

Просмотреть файл

@ -66,7 +66,7 @@ describe("E2E - pbiviz info", () => {
expect(error).toBeDefined();
expect(error.status).toBe(1);
expect(error.message).toContain("Error: pbiviz.json not found. You must be in the root of a visual project to run this command");
expect(error.message).toContain("pbiviz.json not found. You must be in the root of a visual project to run this command");
});

Просмотреть файл

@ -73,7 +73,7 @@ describe("E2E - pbiviz package", () => {
}
expect(error).toBeDefined();
expect(error.status).toBe(1);
expect(error.message).toContain("Error: pbiviz.json not found. You must be in the root of a visual project to run this command");
expect(error.message).toContain("pbiviz.json not found. You must be in the root of a visual project to run this command");
});
it("Should throw error if there is nothing to produce", () => {

Просмотреть файл

@ -90,7 +90,7 @@ describe("E2E - pbiviz start", () => {
}
expect(error).toBeDefined();
expect(error.status).toBe(1);
expect(error.message).toContain("Error: pbiviz.json not found. You must be in the root of a visual project to run this command");
expect(error.message).toContain("pbiviz.json not found. You must be in the root of a visual project to run this command");
});
it("Should generate statistic files without flags", (done) => {

Просмотреть файл

@ -9,6 +9,7 @@ interface StartOptions {
stats: boolean,
drop: boolean,
skipApi: boolean
allLocales: boolean
}
interface PackageOptions {
@ -18,6 +19,7 @@ interface PackageOptions {
compression: number,
stats: boolean,
skipApi: boolean
allLocales: boolean
}
interface NewOptions {
@ -37,7 +39,8 @@ export default class CommandManager {
minify: false,
devServerPort: options.port,
stats: options.stats,
skipApiCheck: options.skipApi
skipApiCheck: options.skipApi,
allLocales: options.allLocales
}
const visualManager = new VisualManager(rootPath)
await visualManager
@ -60,7 +63,8 @@ export default class CommandManager {
minify: options.minify,
compression: options.compression,
stats: options.stats,
skipApiCheck: options.skipApi
skipApiCheck: options.skipApi,
allLocales: options.allLocales
}
new VisualManager(rootPath)
.prepareVisual()

Просмотреть файл

@ -63,7 +63,8 @@ export default class VisualManager {
if (this.doesPBIVIZExists()) {
this.pbivizConfig = readJsonFromVisual(PBIVIZ_FILE, this.basePath);
} else {
throw new Error(PBIVIZ_FILE + ' not found. You must be in the root of a visual project to run this command.')
ConsoleWriter.error(PBIVIZ_FILE + ' not found. You must be in the root of a visual project to run this command.')
process.exit(1);
}
return this;
}

Просмотреть файл

@ -10,7 +10,7 @@ import { exec as processExec } from 'child_process';
import lodashCloneDeep from 'lodash.clonedeep';
import ExtraWatchWebpackPlugin from 'extra-watch-webpack-plugin';
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
import { PowerBICustomVisualsWebpackPlugin } from 'powerbi-visuals-webpack-plugin';
import { PowerBICustomVisualsWebpackPlugin, LocalizationLoader } from 'powerbi-visuals-webpack-plugin';
import ConsoleWriter from './ConsoleWriter.js';
import { resolveCertificate } from "./CertificateTools.js";
import { readJsonFromRoot, readJsonFromVisual } from './utils.js'
@ -33,6 +33,7 @@ export interface WebpackOptions {
devServerPort?: number;
fast?: boolean;
skipApiCheck?: boolean;
allLocales?: boolean;
}
export default class WebPackWrap {
@ -226,25 +227,30 @@ export default class WebPackWrap {
}
}
async useLoader({
fast = false
async configureLoaders({
fast = false,
includeAllLocales = false
}) {
let tsOptions = {};
if (fast) {
tsOptions = {
transpileOnly: false,
experimentalWatchApi: false
};
}
this.webpackConfig.module.rules.push({
test: /(\.ts)x?$/,
use: [
{
loader: "ts-loader",
options: tsOptions
options: fast
? {
transpileOnly: false,
experimentalWatchApi: false
}
: {}
}
]
});
if(!includeAllLocales){
this.webpackConfig.module.rules.push({
test: /powerbiGlobalizeLocales\.js$/, // path to file with all locales declared in formattingutils
loader: LocalizationLoader
});
}
}
async prepareWebPackConfig(visualPackage, options: WebpackOptions, tsconfig) {
@ -260,8 +266,9 @@ export default class WebPackWrap {
await this.appendPlugins(options, visualPackage, tsconfig);
await this.configureDevServer(visualPackage, options.devServerPort);
await this.configureVisualPlugin(options, tsconfig, visualPackage);
await this.useLoader({
fast: options.fast
await this.configureLoaders({
fast: options.fast,
includeAllLocales: options.allLocales
});
return this.webpackConfig;
@ -289,7 +296,8 @@ export default class WebPackWrap {
fast: false,
compression: 0,
stats: true,
skipApiCheck: false
skipApiCheck: false,
allLocales: false
}) {
const tsconfig = readJsonFromVisual('tsconfig.json');
this.pbiviz = readJsonFromVisual('pbiviz.json');

Просмотреть файл

@ -1,6 +1,5 @@
import { getRootPath, readJsonFromRoot } from './utils.js';
import { LocalizationLoader } from "powerbi-visuals-webpack-plugin";
import MiniCssExtractPlugin from "mini-css-extract-plugin";
import TerserPlugin from "terser-webpack-plugin";
import path from "path";
@ -65,10 +64,6 @@ const webpackConfig = {
{
test: /\.(woff|ttf|ico|woff2|jpg|jpeg|png|webp|gif|svg|eot)$/i,
type: 'asset/inline'
},
{
test: /powerbiGlobalizeLocales\.js$/,
loader: LocalizationLoader
}
]
},