Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename gasket/intl to gasket/react-intl #222

Merged
merged 3 commits into from
Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/gasket-plugin-intl/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

### 4.0.2

- Create new apps with `@gasket/intl@4`
- Create new apps with `@gasket/react-intl@4`

### 4.0.1

Expand Down
4 changes: 2 additions & 2 deletions packages/gasket-plugin-intl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ module.exports = {

## Usage

Loader packages, such as [@gasket/intl] for React and Next.js apps, can utilize
Loader packages, such as [@gasket/react-intl] for React and Next.js apps, can utilize
settings from the [locales manifest] for loading locale files. Also, for apps
with a server element, request based settings can be made available with the
[response data].
Expand Down Expand Up @@ -298,7 +298,7 @@ entry.
[response data]:#response-data
[intlLocale lifecycle]:#intllocale

[@gasket/intl]: /packages/gasket-intl/README.md
[@gasket/react-intl]: /packages/gasket-react-intl/README.md

[global window object]:https://developer.mozilla.org/en-US/docs/Glossary/Global_object

2 changes: 1 addition & 1 deletion packages/gasket-plugin-intl/lib/configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ module.exports = function configureHook(gasket, config) {
modules = modules === true ? moduleDefaults : { ...moduleDefaults, ...modules };
}

// This allows packages (@gasket/intl) to reference certain configs
// This allows packages (@gasket/react-intl) to reference certain configs
/* eslint-disable no-process-env */
process.env.GASKET_INTL_LOCALES_DIR = fullLocalesDir;
process.env.GASKET_INTL_MANIFEST_FILE = path.join(fullLocalesDir, manifestFilename);
Expand Down
19 changes: 11 additions & 8 deletions packages/gasket-plugin-intl/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,21 @@ module.exports = {
async create(gasket, context) {
const { files, pkg } = context;
const rootDir = path.join(__dirname, '..');
const isReactProject = pkg.has('dependencies', 'react');

files.add(
`${ rootDir }/generator/*`,
`${ rootDir }/generator/**/*`
`${rootDir}/generator/*`,
`${rootDir}/generator/**/*`
);

// TODO (@kinetifex): check if react is being added first
pkg.add('dependencies', {
'@gasket/intl': devDependencies['@gasket/intl'],
'react-intl': devDependencies['react-intl']
});
if (isReactProject) {
pkg.add('dependencies', {
'@gasket/react-intl': devDependencies['@gasket/react-intl'],
'react-intl': devDependencies['react-intl']
});

context.hasGasketIntl = true;
context.hasGasketIntl = true;
}
},
build: {
timing: {
Expand Down
2 changes: 1 addition & 1 deletion packages/gasket-plugin-intl/lib/workbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function makeEncodeLocaleUrls(localesPath) {
const reModulePath = new RegExp(`(.*${ localesPath }/)(.*)(/.*)`);
/**
* Encode the identifier part of the locale file uri
* This is necessary to match request for these assets by `@gasket/intl`
* This is necessary to match request for these assets by `@gasket/react-intl`
*
* @param {Object} originalManifest - Workbox manifest
* @returns {Object} results - Transformed manifest
Expand Down
2 changes: 1 addition & 1 deletion packages/gasket-plugin-intl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"url-join": "^4.0.0"
},
"devDependencies": {
"@gasket/intl": "^6.0.0-canary.4",
"@gasket/react-intl": "^6.0.0-canary.4",
"@gasket/plugin-log": "^6.0.0-canary.2",
"assume": "^2.2.0",
"assume-sinon": "^1.0.1",
Expand Down
56 changes: 36 additions & 20 deletions packages/gasket-plugin-intl/test/create.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,47 @@ const path = require('path');
const plugin = require('../lib/index');

describe('create', function () {
// Simple test-helper to assert created with a clean set of spies.
function expectCreatedWith(assertFn) {
return async function expectCreated() {
const spy = {
pkg: { add: sinon.stub() },
files: { add: sinon.stub() }
};
let mockContext;
let pkgHasStub;
let pkgAddStub;
let filesAddStub;

await plugin.hooks.create({}, spy);
assertFn(spy);
beforeEach(function () {
pkgHasStub = sinon.stub().returns(true);
pkgAddStub = sinon.stub();
filesAddStub = sinon.stub();

mockContext = {
pkg: {
add: pkgAddStub,
has: pkgHasStub
},
files: {
add: filesAddStub
}
};
}
});

it('adds the appropriate globs', expectCreatedWith(({ files }) => {
it('adds the appropriate globs', async function () {
const rootDir = path.join(__dirname, '..');
assume(files.add).calledWith(
`${ rootDir }/generator/*`,
`${ rootDir }/generator/**/*`
await plugin.hooks.create({}, mockContext);
assume(filesAddStub.args[0][0]).eqls(
`${rootDir}/generator/*`,
`${rootDir}/generator/**/*`
);
}));
});

it('does not add intl dependencies when react is not found', async function () {
pkgHasStub.returns(false);
await plugin.hooks.create({}, mockContext);
assume(pkgAddStub).not.called();
});

it('adds the appropriate dependencies', expectCreatedWith(({ pkg }) => {
assume(pkg.add).calledWith('dependencies', {
'@gasket/intl': require('../package.json').devDependencies['@gasket/intl'],
it('adds the appropriate dependencies', async function () {
await plugin.hooks.create({}, mockContext);
assume(pkgAddStub.args[0]).eqls(['dependencies', {
'@gasket/react-intl': require('../package.json').devDependencies['@gasket/react-intl'],
'react-intl': require('../package.json').devDependencies['react-intl']
});
}));
}]);
});
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
{{#if hasGasketIntl}}
import { withIntlProvider } from '@gasket/intl';
import { withIntlProvider } from '@gasket/react-intl';
{{/if}}
{{#if hasGasketRedux}}
const { nextRedux } = require('../redux/store');
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `@gasket/intl`
# `@gasket/react-intl`

### 6.0.0

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @gasket/intl
# @gasket/react-intl

React component library to enable localization for Gasket apps. Loads and
manages locale files from [@gasket/plugin-intl].
Expand All @@ -15,7 +15,7 @@ manages locale files from [@gasket/plugin-intl].
## Installation

```
npm i @gasket/intl
npm i @gasket/react-intl
```

## Components
Expand All @@ -34,7 +34,7 @@ the locale components below.
- `[options]` - (object) Optional configuration - currently not used

```jsx
import { withIntlProvider } from '@gasket/intl';
import { withIntlProvider } from '@gasket/react-intl';

const App = props => <div>{props.children}</div>

Expand All @@ -61,7 +61,7 @@ wrapped component will be rendered.
#### Example

```jsx
import { withLocaleRequired } from '@gasket/intl';
import { withLocaleRequired } from '@gasket/react-intl';
import { FormattedMessage } from 'react-intl';

const Component = props => <h1><FormattedMessage id='welcome'/></h1>
Expand Down Expand Up @@ -98,7 +98,7 @@ content until a [split locales] file loads.
- `loading` - (string|node) Content to render while loading, otherwise null.

```jsx
import { LocaleRequired } from '@gasket/intl';
import { LocaleRequired } from '@gasket/react-intl';
import { FormattedMessage } from 'react-intl';

const Component = props => (
Expand All @@ -118,7 +118,7 @@ export default Component;
## Next.js

Loader functions specific to Next.js lifecycles are available from
`@gasket/intl/next`.
`@gasket/react-intl/next`.

### intlGetStaticProps

Expand All @@ -137,7 +137,7 @@ To generate static pages for a locale in a Next.js app, you can use

```jsx
// pages/[locale]/example.js
import { intlGetStaticProps } from '@gasket/intl/next';
import { intlGetStaticProps } from '@gasket/react-intl/next';
import { FormattedMessage } from 'react-intl';

export default const Component = props => <h1><FormattedMessage id='welcome'/></h1>
Expand Down Expand Up @@ -176,7 +176,7 @@ be loaded will come from the `res.gasketData` provided by [@gasket/plugin-intl].
[locales path] in the plugin docs.

```jsx
import { intlGetServerSideProps } from '@gasket/intl/next';
import { intlGetServerSideProps } from '@gasket/react-intl/next';
import { FormattedMessage } from 'react-intl';

export default const Component = props => <h1><FormattedMessage id='welcome'/></h1>
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@gasket/intl",
"name": "@gasket/react-intl",
"version": "6.0.0-canary.4",
"description": "React component library to enable localization for gasket apps.",
"main": "./lib",
Expand All @@ -25,7 +25,7 @@
},
"keywords": [
"gasket",
"intl"
"react-intl"
],
"author": "GoDaddy Operating Company, LLC",
"maintainers": [
Expand All @@ -35,7 +35,7 @@
"bugs": {
"url": "https://github.com/godaddy/gasket/issues"
},
"homepage": "https://github.com/godaddy/gasket/tree/master/packages/gasket-intl#readme",
"homepage": "https://github.com/godaddy/gasket/tree/master/packages/gasket-react-intl#readme",
"dependencies": {
"@babel/runtime": "^7.5.5",
"@gasket/fetch": "^6.0.0-canary.2",
Expand Down