Can transloco.config.js in a monorepo environment support multiple apps built from different libraries - transloco

With reference to the structure explained in https://ngneat.github.io/transloco/docs/tools/scope-lib-extractor, if we have two apps
app (built on core library)
app2[built on core2 library)
What is the best way to get translations from library included to respective consumer app ?
Scoped Library Extractor doesn't seem to support multiple configuration
module.exports = {
rootTranslationsPath: './src/app/assets/i18n/',
langs: ['en', 'es'],
scopedLibs: ['./projects/core/']
};
module.exports = {
rootTranslationsPath: './src/app2/assets/i18n/',
langs: ['en', 'es'],
scopedLibs: ['./projects/core2/']
};

Related

How to get Nrwl Nest.js Jest workspace working with firebase es6 packages?

I have a nrwl Angular-Jest application setup via npx create-nx-workspace.
While working on this project, I had upgraded from:
"firebase": "9.1.3",
"firebase-admin": "9.12.0",
"firebase-functions": "3.15.7",
to
"firebase": "9.16.0",
"firebase-admin": "11.5.0",
"firebase-functions": "4.2.0",
to get the extension emulator working locally. Although it works, I now have issues running jest. It says that firebase now has es6 imports and wont work. Error Message Below:
● Test suite failed to run
Jest encountered an unexpected token
Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.
Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.
By default "node_modules" folder is ignored by transformers.
Here's what you can do:
• If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
• If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/configuration
For information about custom transformations, see:
https://jestjs.io/docs/code-transformation
Details:
/Users/[justOnlyMe]/Desktop/[nrwlProject]/node_modules/firebase-admin/lib/esm/auth/index.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){import mod from "../../auth/index.js";
^^^^^^
SyntaxError: Cannot use import statement outside a module
at Runtime.createScriptFromCode (../../../node_modules/jest-runtime/build/index.js:1728:14)
at Object.<anonymous> (../../../node_modules/firebase-functions/lib/common/providers/identity.js:25:14)
I've also tried using transformIgnorePatterns to get a transformation just for firebase node_modules but now jest continues to run and seems unresponsive. (I believe this may be an issue with ts-jest in jest).
transform: {
'^.+\\.[tj]s$': 'ts-jest',
},
transformIgnorePatterns: [
'../../../node_modules/(?!#firebase.*/)',
'../../../node_modules/(?!firebase/)',
'../../../node_modules/(?!firebase-admin/)',
'../../../node_modules/(?!firebase-functions/)',
],
Question: Does anyone know how to get es6 node_modules to work with jest in a nrwl nest.js typescript project?
My jest config:
module.exports = {
displayName: '[projectName]',
preset: '../../../jest.preset.js',
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.spec.json',
},
},
transform: {
'^.+\\.[tj]s$': 'ts-jest',
},
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../../coverage/apps/back/[projectName]',
testEnvironment: 'node',
}
In your jest config add in the transform object the babel-jest config:
"transform": {
"^.+\\.js?$": "babel-jest",
"^.+\\.ts?$": "ts-jest"
}

lit-element with rollup and redux: process is not defined

I'm trying to switch my state management in a lit-element based application from simple global variables to redux.
Following the redux tutorials I installed the redux toolkit and created a simple reducer and store.
Building the app with rollup succeeds but when I load the app in Chrome I get the following error:
ReferenceError: process is not defined
There are several lines in the redux code that use 'process', f.e.
/*
* This is a dummy function to check if the function name has been altered by minification.
* If the function has been minified and NODE_ENV !== 'production', warn the user.
*/
function isCrushed() {}
/
if (process.env.NODE_ENV !== 'production' && typeof isCrushed.name === 'string' && isCrushed.name !== 'isCrushed') {
warning('You are currently using minified code outside of NODE_ENV === "production". ' + 'This means that you are running a slower development build of Redux. ' + 'You can use loose-envify (https://github.com/zertosh/loose-envify) for browserify ' + 'or setting mode to production in webpack (https://webpack.js.org/concepts/mode/) ' + 'to ensure you have the correct code for your production build.');
}
Can anyone help? Am I missing something? Is 'process' something that is only available in Node?
A more appropriate fix than the one I posted as a comment seems to be string replacement via the rollup.config.js.
Source: https://github.com/rollup/rollup/issues/487
npm install rollup-plugin-replace --save-dev
Then in the plugins section of your rollup.config.js add this
replace({
'process.env.NODE_ENV': JSON.stringify('production')
}),
I'm a Redux maintainer. The Redux library ships several different build artifacts for use in different environments. We expect that the CommonJS and ES Module build artifacts are going to be run through a bundler that knows how to handle process.env.NODE_ENV checks and replace them at build time, per standard ecosystem convention.
If you are trying to use Redux Toolkit in a non-bundled environment, you should use one of the build artifacts that has already been compiled with a specific value of process.env.NODE_ENV ('production' or 'development'). We ship a couple of ESM build artifacts this way, as well as the UMD build artifact:
https://unpkg.com/browse/#reduxjs/toolkit#1.7.1/dist/
You probably should be using redux-toolkit.modern.production.min.js (ESM) or redux-toolkit.umd.min.js (UMD).
If you are actually trying to do a full build, then yes, you need to configure Rollup to do an appropriate replacement on process.env.NODE_ENV.
I found this plugin that solved the issue for me
rollup-plugin-node-globals

Aliasing locales in Next.js

I'm using next-i18next to localize our Next.js app with the following config:
module.exports = {
i18n: {
defaultLocale: "en",
locales: ["en", "zh-CN"],
},
};
This works well. Agents with zh-CN among Allow-Language header are taken to the Simplified Chinese version of the page.
Is there a way to make zh-SG agents redirect to the Simplified Chinese version without creating a separate locale JSON file? Similarly, zh-HK and zh-TW will use the same translations (Traditional Chinese). I'm trying to avoid maintaining duplicate files by only having one file for Simplified and one for Traditional Chinese. Thank you!

Exporting public C headers with SwiftPM

I have an open source Objective C framework, which I'd like to provide using Swift Package Manager as well.
Normally, I have public headers set in the Xcode project, which, when the framework is built, are copied under the framework bundle, and are discovered when linked to by Xcode.
I can't, however get it to work with SwiftPM.
I created a modulemap for my framework:
framework module LNPopupController {
umbrella header "LNPopupController.h"
export *
module * { export * }
}
and I define the library like so in the Package.swift:
let package = Package(
name: "LNPopupController",
platforms: [
.iOS(.v12),
.macOS(.v10_15)
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "LNPopupController",
type: .dynamic,
targets: ["LNPopupController"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "LNPopupController",
dependencies: [],
path: "LNPopupController",
publicHeadersPath: ".",
cSettings: [
.headerSearchPath("."),
.headerSearchPath("Private"),
]),
]
)
When added as a project dependency in Xcode, the framework compiles just fine, but when the dependent target attempts to import LNPopupController, an error is thrown: umbrella header 'LNPopupController.h' not found
Looking at the build folder, indeed, I see that Xcode has built a binary, but has not copied the public headers.
Any way to specify which headers are public, and make the build system copy them for import?
I eventually figured it out. This is what I did for LNPopupController:
I created a include/LNPopupController/ sub-directory tree, and put soft links to all public headers there.
In the package file, I added publicHeadersPath: "include".
You can see the final result here:
https://github.com/LeoNatan/LNPopupController/blob/master/Package.swift
It might not be the most optimal way, but it works for all my ObjC projects which I have tried this method on.

Set suffix for module resolution in Meteor

I'm trying to include the bcoin library in my Meteor project. bcoin uses two type of modules, <module>.js and <module>-browser.js, depending whether one is building a node app or a browser app. In my case I need to import bcoin in the frontend part of my project, but a normal import bcoin from 'bcoin' resolves the module bcoin.js by default. Even if I use import bcoin from 'bcoin/lib/bcoin-browser' the file bcoin-browser.js will require other .js files rather than their -browser.js variant. The webpack configuration uses the directive
resolve: {
modules: ['node_modules'],
extensions: ['-browser.js', '.js', '.json']
},
is there something similar in Meteor?
Thanks

Resources