Skip to content
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
1 change: 1 addition & 0 deletions .parcelrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": "@parcel/config-default",
"resolvers": ["parcel-resolver-docs", "..."],
"transformers": {
"apiCheck:*.{js,ts,tsx,json}": ["parcel-transformer-docs"],
"docs:*.{js,ts,tsx,json}": ["parcel-transformer-docs", "@parcel/transformer-inline"],
"docs-json:*.{js,ts,tsx,json}": ["parcel-transformer-docs"],
"*.{md,mdx}": ["parcel-transformer-mdx-docs"],
Expand Down
2 changes: 1 addition & 1 deletion .storybook/theme.register.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {themes} from '@storybook/theming';
import addons from '@storybook/addons';
import {FORCE_RE_RENDER} from '@storybook/core-events';
// temporary until we have a better place to grab it from
import * as packageJSON from '../packages/@react-spectrum/alert/package.json';
import * as packageJSON from '../packages/@adobe/react-spectrum/package.json';

// Automatically switch light/dark theme based on system pref.
addons.register('theme-switcher', api => {
Expand Down
10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"start:docs": "PARCEL_WORKER_BACKEND=process DOCS_ENV=dev parcel 'packages/@react-{spectrum,aria,stately}/*/docs/*.mdx' 'packages/dev/docs/pages/**/*.mdx'",
"build:docs": "PARCEL_WORKER_BACKEND=process DOCS_ENV=staging parcel build 'packages/@react-{spectrum,aria,stately}/*/docs/*.mdx' 'packages/dev/docs/pages/**/*.mdx' --no-scope-hoist",
"test": "yarn jest",
"build": "make build",
"test:ssr": "yarn jest --config jest.ssr.config.js",
"ci-test": "yarn jest --maxWorkers=2 && yarn test:ssr --runInBand",
"ci-test-17": "yarn jest --maxWorkers=2 && yarn test:ssr --runInBand",
Expand All @@ -37,7 +38,11 @@
"chromatic": "chromatic --project-token 'q5msektqrfg' --build-script-name 'build:chromatic'",
"merge:css": "babel-node --presets @babel/env ./scripts/merge-spectrum-css.js",
"release": "lerna publish from-package --yes",
"publish:nightly": "lerna publish -y --canary --preid nightly --dist-tag=nightly --exact --force-publish=* --no-push"
"publish:nightly": "lerna publish -y --canary --preid nightly --dist-tag=nightly --exact --force-publish=* --no-push",
"build:api-published": "node scripts/buildPublishedAPI.js",
"build:api-branch": "node scripts/buildBranchAPI.js",
"compare:apis": "node scripts/compareAPIs.js",
"check-apis": "yarn build:api-published && yarn build:api-branch && yarn compare:apis"
},
"workspaces": [
"packages/react-stately",
Expand Down Expand Up @@ -115,13 +120,15 @@
"eslint-plugin-rulesdir": "^0.1.0",
"fast-glob": "^3.1.0",
"file-loader": "^0.9.0",
"fs-extra": "^10.0.0",
"full-icu": "^1.3.0",
"identity-obj-proxy": "^3.0.0",
"ignore-styles": "^5.0.1",
"jest": "^26.4.2",
"jest-junit": "^12.0.0",
"jest-matchmedia-mock": "^1.0.0",
"jsdom": "^16.3.0",
"json-diff-ts": "^1.1.0",
"lerna": "^3.13.2",
"lfcdn": "^0.4.2",
"md5": "^2.2.1",
Expand Down Expand Up @@ -158,6 +165,7 @@
"tempy": "^0.5.0",
"typescript": "^3.8.3",
"url-loader": "^1.1.2",
"walk-object": "^4.0.0",
"webpack": "^4.44.2",
"webpack-dev-middleware": "^3.6.1",
"webpack-hot-middleware": "^2.24.3",
Expand Down
7 changes: 5 additions & 2 deletions packages/dev/parcel-resolver-docs/DocsResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const path = require('path');

module.exports = new Resolver({
async resolve({dependency, options, filePath}) {
if (dependency.moduleSpecifier.startsWith('docs:') || dependency.pipeline === 'docs' || dependency.pipeline === 'docs-json') {
if (dependency.moduleSpecifier.startsWith('docs:') || dependency.moduleSpecifier.startsWith('apiCheck:') || dependency.pipeline === 'docs' || dependency.pipeline === 'docs-json' || dependency.pipeline === 'apiCheck') {
const resolver = new NodeResolver({
extensions: ['ts', 'tsx', 'd.ts', 'js'],
mainFields: ['source', 'types', 'main'],
Expand All @@ -33,7 +33,10 @@ module.exports = new Resolver({
if (resolved) {
// HACK: ensure source code is used to build types, not compiled code.
// Parcel removes the source field from package.json when the code comes from node_modules.
if (resolved.filePath.endsWith('.d.ts') && !resolved.filePath.includes('@react-types')) {
if ((
/^@(react-spectrum|react-aria|react-stately|internationalized|react-types|spectrum-icons|adobe\/react-spectrum)/g.test(resolved.filePath)
|| /^(react-aria|react-stately)/g.test(resolved.filePath)
) && resolved.filePath.endsWith('.d.ts') && !resolved.filePath.includes('@react-types')) {
resolved.filePath = path.resolve(path.dirname(resolved.filePath), '..', 'src', 'index.ts');
}

Expand Down
3 changes: 3 additions & 0 deletions packages/dev/parcel-transformer-docs/DocsTransformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ module.exports = new Transformer({
exports[path.node.declaration.id.name] = processExport(path.get('declaration'));
} else {
let identifiers = t.getBindingIdentifiers(path.node.declaration);
let index = 0;
for (let id of Object.keys(identifiers)) {
exports[identifiers[id].name] = processExport(path.get('declaration.declarations')[index]);
index += 1;
Comment on lines +59 to +62
Copy link
Member

@LFDanLu LFDanLu Sep 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mega nit: As an aside (and no need to change), but you can do this index via for (let [index, id] of Object.keys(identifiers).entries())

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha, good call

asset.symbols.set(identifiers[id].name, identifiers[id].name);
}
}
Expand Down
142 changes: 142 additions & 0 deletions scripts/buildBranchAPI.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/*
* Copyright 2020 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

const tempy = require('tempy');
const fs = require('fs-extra');
const packageJSON = require('../package.json');
const path = require('path');
const glob = require('fast-glob');
const spawn = require('cross-spawn');

build().catch(err => {
console.error(err.stack);
process.exit(1);
});

/**
* Building this will run the docs builder using the apiCheck pipeline in .parcelrc
* This will generate json containing the visible (API/exposed) type definitions for each package
* This is run against the current branch by copying the current branch into a temporary directory and building there
*/
async function build() {
// Create a temp directory to build the site in
let dir = tempy.directory();
console.log(`Building branch api into ${dir}...`);

// Generate a package.json containing just what we need to build the website
let pkg = {
name: 'rsp-website',
version: '0.0.0',
private: true,
workspaces: [
'packages/*/*'
],
devDependencies: Object.fromEntries(
Object.entries(packageJSON.devDependencies)
.filter(([name]) =>
name.startsWith('@parcel') ||
name === 'parcel' ||
name === 'patch-package' ||
name.startsWith('@spectrum-css') ||
name.startsWith('postcss') ||
name.startsWith('@adobe')
)
),
dependencies: {},
resolutions: packageJSON.resolutions,
browserslist: packageJSON.browserslist,
scripts: {
build: 'yarn parcel build packages/@react-spectrum/actiongroup',
postinstall: 'patch-package'
}
};

// Add dependencies on each published package to the package.json, and
// copy the docs from the current package into the temp dir.
let packagesDir = path.join(__dirname, '..', 'packages');
let packages = glob.sync('*/**/package.json', {cwd: packagesDir});

pkg.devDependencies['babel-plugin-transform-glob-import'] = '*';

fs.writeFileSync(path.join(dir, 'package.json'), JSON.stringify(pkg, false, 2));

fs.writeFileSync(path.join(dir, 'babel.config.json'), `{
"plugins": [
"transform-glob-import"
]
}`);

// Copy necessary code and configuration over
fs.copySync(path.join(__dirname, '..', 'yarn.lock'), path.join(dir, 'yarn.lock'));
fs.copySync(path.join(__dirname, '..', 'packages', 'dev'), path.join(dir, 'packages', 'dev'));
fs.removeSync(path.join(dir, 'packages', 'dev', 'v2-test-deps'));
fs.copySync(path.join(__dirname, '..', 'packages', '@adobe', 'spectrum-css-temp'), path.join(dir, 'packages', '@adobe', 'spectrum-css-temp'));
fs.copySync(path.join(__dirname, '..', '.parcelrc'), path.join(dir, '.parcelrc'));
fs.copySync(path.join(__dirname, '..', 'cssnano.config.js'), path.join(dir, 'cssnano.config.js'));
fs.copySync(path.join(__dirname, '..', 'postcss.config.js'), path.join(dir, 'postcss.config.js'));
fs.copySync(path.join(__dirname, '..', 'lib'), path.join(dir, 'lib'));
fs.copySync(path.join(__dirname, '..', 'CONTRIBUTING.md'), path.join(dir, 'CONTRIBUTING.md'));

// Only copy babel patch over
let patches = fs.readdirSync(path.join(__dirname, '..', 'patches'));
let babelPatch = patches.find(name => name.startsWith('@babel'));
fs.copySync(path.join(__dirname, '..', 'patches', babelPatch), path.join(dir, 'patches', babelPatch));

// Copy packages over to temp dir
console.log('copying over');
for (let p of packages) {
if (!p.includes('spectrum-css') && !p.includes('dev/')) {
let json = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'packages', p)), 'utf8');
if (json.private) {
continue;
}
fs.copySync(path.join(__dirname, '..', 'packages', path.dirname(p)), path.join(dir, 'packages', path.dirname(p)));
if (!p.includes('@react-types')) {
delete json.types;
}
delete json.main;
delete json.module;
delete json.devDependencies;
json.apiCheck = 'dist/api.json';
json.targets = {
apiCheck: {}
};
fs.writeFileSync(path.join(dir, 'packages', p), JSON.stringify(json, false, 2));
}
}

// Install dependencies from npm
await run('yarn', {cwd: dir, stdio: 'inherit'});

// Build the website
console.log('building api files');
await run('yarn', ['parcel', 'build', 'packages/@react-{spectrum,aria,stately}/*/', 'packages/@internationalized/*/', '--target', 'apiCheck'], {cwd: dir, stdio: 'inherit'});

// Copy the build back into dist, and delete the temp dir.
fs.copySync(path.join(dir, 'packages'), path.join(__dirname, '..', 'dist', 'branch-api'));
fs.removeSync(dir);
}

function run(cmd, args, opts) {
return new Promise((resolve, reject) => {
let child = spawn(cmd, args, opts);
child.on('error', reject);
child.on('close', code => {
if (code !== 0) {
reject(new Error('Child process failed'));
return;
}

resolve();
});
});
}
Loading